2

I would like to obtain a graph that is similar to this:

enter image description here

I currently have this as my latex file:

\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}

Which produces the following output: enter image description here

The CSV data is as follows:

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 Answer 1

7

You can use an ybar plot with a very small 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}

enter image description here

Perhaps increasing ymax a bit will look better.

\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}

enter image description here

Alternatively you can use 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}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .