我的代码的当前状态是:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xmin = 450, xmax = 1000,
ymin = 0.0, ymax = 0.6,
xtick distance = 50,
ytick distance = 0.1,
x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
y label style={at={(axis description cs:-0.05,.5)},rotate=90,anchor=south},
% grid = both,
% minor tick num = 1,
% major grid style = {lightgray},
% minor grid style = {lightgray!25},
width = 0.8 \textwidth,
height = 0.3\textwidth,
xlabel = {Wavelength [nm]},
ylabel = {Reflectance [\%/100]}]
% Plot data from file
\addplot[color=blue, smooth, thick] table[x=x, y=y, col sep=comma]{figures-src/chapter2/reflectance_suger_beets.csv};
\end{axis}
\end{tikzpicture}
\end{document}
我想要做的是
- 将条形图(例如红色 632-692nm 光谱带、红边等)插入到我的图中,
- 在顶部和右侧添加轴,使得图看起来就像包含在第一个图的正方形中(我不确定我是否以一种可以理解的方式表述了这一点......)。
任何帮助都将非常感激!
答案1
以下是基于您的代码的示例:
\documentclass{article}
\usepackage{pgfplots}
\usepackage{tikz}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis on top,
xmin = 450, xmax = 1000,
ymin = 0.0, ymax = 0.6,
xtick distance = 50,
ytick distance = 0.1,
x label style={at={(axis description cs:0.5,-0.1)},anchor=north},
width = 0.8 \textwidth,
height = 0.5\textwidth,
xlabel = {Wavelength [nm]},
ylabel = {Reflectance [\%/100]}]
\fill[red!20!white] (axis cs:632,0.6) rectangle (axis cs:692,0);
\fill[red!40!white] (axis cs:706,0.6) rectangle (axis cs:746,0);
\fill[red!60!white] (axis cs:772,0.6) rectangle (axis cs:890,0);
\node[rotate=90] at (axis cs:662,0.3) {Red 632--692\,nm};
\node[rotate=90] at (axis cs:726,0.3) {Red-edge 706--746\,nm};
\node[rotate=90] at (axis cs:840,0.3) {NIR1 772--890\,nm};
\addplot[color=blue, smooth, thick, domain=450:1000] {0.001*(x-450)};
\end{axis}
\end{tikzpicture}
\end{document}