2

My first time drawing a graph in LaTeX... it is just really difficult.

My attempt:

\documentclass{scrartcl}

\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
    scale only axis,
    axis lines=middle,
    xlabel={Concentration [ppm]},
    ylabel={Absorption},
    xmin=-4, xmax=8,
    ymin=0, ymax=0.5,
    xtick={-4,-2,0,2,4,6,8},
    ytick={0.1,0.2,0.3,0.4,0.5},
    legend pos=north west,
    ymajorgrids=true,
    grid=major,
]

\addplot[
    color=blue,
    mark=square,
    ]
    coordinates {
    (-2.13,0)(0,0.1127)(2,0.2165)(4,0.3177)(6,0.4193)
    };
    
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

But it should look like this

enter image description here

Please notice, that I actually wanted to draw the calibration graph curve on a graph paper in LaTeX.

Thank you very much!

1 Answer 1

4

Like this:

Changes:

grid style={line width=.1pt, draw=orange!50}, makes grid orange and a line width of 0.1 pt

minor x tick num={9}, minor y tick num={9}, makes 9 minor ticks for x and y axis.

set to grid=both,

xlabel style={at={(ticklabel* cs:1)},anchor=north west}, anchors x axis label bottom right.

ylabel style={at={(ticklabel* cs:1)},anchor=south west} anchors y axis label top left.

EDIT: I added major grid style={line width=.2pt, draw=orange}, to create a darker major grid to make it look more like a scale paper.

\documentclass{scrartcl}

\usepackage{pgfplots}

\begin{document}
    
    \begin{tikzpicture}
        \begin{axis}[grid style={line width=.1pt, draw=orange!30},major grid style={line width=.2pt, draw=orange},
            minor x tick num={9},
            minor y tick num={9},
            scale only axis,
            axis lines=middle,
            xlabel={Concentration [ppm]},
            ylabel={Absorption},
            xmin=-4, xmax=8,
            ymin=0, ymax=0.5,
            xtick={-4,-2,0,2,4,6,8},
            ytick={0,0.1,0.2,0.3,0.4,0.5},
            legend pos=north west,
            ymajorgrids=true,
            grid=both,
            xlabel style={at={(ticklabel* cs:1)},anchor=north west,xshift=-3.2cm,yshift=-0.6cm},
            ylabel style={at={(ticklabel* cs:1)},anchor=south east,yshift=-0.8cm,xshift=-0.3cm}
            ]
            
            \addplot[
            color=blue,
            mark=square,
            ]
            coordinates {
                (-2.13,0)(0,0.1127)(2,0.2165)(4,0.3177)(6,0.4193)
            };            
        \end{axis}
    \end{tikzpicture}
\end{document}

enter image description here

5
  • Thank you very much! Is there a way to make the figure a little bit more bigger? It just looks very small compared to my other figures... May 31, 2021 at 23:45
  • 1
    Do you mean the whole picture \begin{tikzpicture}[scale=2]
    – Roland
    May 31, 2021 at 23:51
  • Thank you very much, Roland! The label on the x-axis (and y-axis) does not look so nice. How do I undo this? Jun 1, 2021 at 0:01
  • Deleting the label style and scaling the whole picture makes the label look weird, because it is no longer tied to the axes anymore... is there a solution for this? Jun 1, 2021 at 0:06
  • I actuall do not know what you mean with x-axis (and y-axis) does not look so nice. I edited the answer to make it look more like your picture you posted.
    – Roland
    Jun 1, 2021 at 0:20

You must log in to answer this question.

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