如何在 pgfplots 中的图中添加下拉线

如何在 pgfplots 中的图中添加下拉线

我想要获得与此类似的图表:

在此处输入图片描述

我目前有这个作为我的乳胶文件:

\documentclass{standalone}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{siunitx}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}
    [
    title={Mass Spectrum},
    ylabel={Intensity},
    xlabel={m/z},
    xmin=0,xmax=75,
    width=13cm,
    height=8cm,
    ymin=0,ymax=100
    ]
    \addplot[no markers] table[x=mass,y=intensity,col sep=comma] {isobutelene_epoxide.csv};
    \end{axis}
    \end{tikzpicture}
\end{document}

输出结果如下: 在此处输入图片描述

CSV数据如下:

mass,intensity
13,0.20002
14,1.39014
15,4.9905
16,0.10001
17,0.50005
18,1.89019
25,0.40004
26,3.9904
27,35.69357
28,3.09031
29,15.19152
30,0.50005
31,6.69067
32,0.90009
33,0.10001
36,0.20002
37,2.29023
38,4.09041
39,25.79258
40,17.39174
41,100
42,77.39774
43,48.89489
44,2.89029
45,1.89019
49,0.20002
50,0.70007
51,0.50005
52,0.10001
53,1.19012
54,0.60006
55,1.09011
56,0.50005
57,8.29083
58,0.60006
59,0.30003
69,0.30003
70,0.40004
71,1.29013
72,49.59496
73,2.39024
74,0.10001

答案1

您可以使用ybar非常小的图bar width

\documentclass{standalone}
\usepackage{filecontents}
\begin{filecontents*}{isobutelene_epoxide.csv}
mass,intensity
13,0.20002
14,1.39014
15,4.9905
16,0.10001
17,0.50005
18,1.89019
25,0.40004
26,3.9904
27,35.69357
28,3.09031
29,15.19152
30,0.50005
31,6.69067
32,0.90009
33,0.10001
36,0.20002
37,2.29023
38,4.09041
39,25.79258
40,17.39174
41,100
42,77.39774
43,48.89489
44,2.89029
45,1.89019
49,0.20002
50,0.70007
51,0.50005
52,0.10001
53,1.19012
54,0.60006
55,1.09011
56,0.50005
57,8.29083
58,0.60006
59,0.30003
69,0.30003
70,0.40004
71,1.29013
72,49.59496
73,2.39024
74,0.10001
\end{filecontents*}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{siunitx}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}
    [ybar,bar width=0.4pt,
    title={Mass Spectrum},
    ylabel={Intensity},
    xlabel={m/z},
    xmin=0,xmax=75,
    width=13cm,
    height=8cm,
    ymin=0,ymax=100
    ]
    \addplot[no markers] table[x=mass,y=intensity,col sep=comma] {isobutelene_epoxide.csv};
    \end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

也许增加ymax一点会看起来更好。

\documentclass{standalone}
\usepackage{filecontents}
\begin{filecontents*}{isobutelene_epoxide.csv}
mass,intensity
13,0.20002
14,1.39014
15,4.9905
16,0.10001
17,0.50005
18,1.89019
25,0.40004
26,3.9904
27,35.69357
28,3.09031
29,15.19152
30,0.50005
31,6.69067
32,0.90009
33,0.10001
36,0.20002
37,2.29023
38,4.09041
39,25.79258
40,17.39174
41,100
42,77.39774
43,48.89489
44,2.89029
45,1.89019
49,0.20002
50,0.70007
51,0.50005
52,0.10001
53,1.19012
54,0.60006
55,1.09011
56,0.50005
57,8.29083
58,0.60006
59,0.30003
69,0.30003
70,0.40004
71,1.29013
72,49.59496
73,2.39024
74,0.10001
\end{filecontents*}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{siunitx}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}
    [ybar,bar width=0.4pt,
    title={Mass Spectrum},
    ylabel={Intensity},
    xlabel={m/z},
    xmin=0,xmax=75,
    width=13cm,
    height=8cm,
    ymin=0,ymax=105
    ]
    \addplot[no markers] table[x=mass,y=intensity,col sep=comma] {isobutelene_epoxide.csv};
    \end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

或者,您可以使用ycomb(with mark=none)。

\documentclass{standalone}
\usepackage{filecontents}
\begin{filecontents*}{isobutelene_epoxide.csv}
mass,intensity
13,0.20002
14,1.39014
15,4.9905
16,0.10001
17,0.50005
18,1.89019
25,0.40004
26,3.9904
27,35.69357
28,3.09031
29,15.19152
30,0.50005
31,6.69067
32,0.90009
33,0.10001
36,0.20002
37,2.29023
38,4.09041
39,25.79258
40,17.39174
41,100
42,77.39774
43,48.89489
44,2.89029
45,1.89019
49,0.20002
50,0.70007
51,0.50005
52,0.10001
53,1.19012
54,0.60006
55,1.09011
56,0.50005
57,8.29083
58,0.60006
59,0.30003
69,0.30003
70,0.40004
71,1.29013
72,49.59496
73,2.39024
74,0.10001
\end{filecontents*}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{siunitx}
\begin{document}
    \begin{tikzpicture}
    \begin{axis}
    [ycomb,mark=none,
    title={Mass Spectrum},
    ylabel={Intensity},
    xlabel={m/z},
    xmin=0,xmax=75,
    width=13cm,
    height=8cm,
    ymin=0,ymax=105
    ]
    \addplot[no markers] table[x=mass,y=intensity,col sep=comma] {isobutelene_epoxide.csv};
    \end{axis}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容