2

So far, I used gnuplot to draw plots for my LaTeX documents. However, sometimes it is not so satisfactory and I have not yet found the optimal solution for making plots. Since I read about pgfplots now and then here on Tex.SE, I want to try that. The Syntax is quite difficult for a Beginner, so I was unable to figure out how to do the following. Consider this MWE

\documentclass[tikz]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\pagestyle{empty}

\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        grid=both,
        grid style={line width=0.2pt, dashed, color=black},
        xlabel=xlabel,
        ylabel=ylabel]
    \addplot[color=red,mark=x] coordinates {
        (2,-2.8559703)
        (3,-3.5301677)
        (4,-4.3050655)
        (5,-5.1413136)
        (6,-6.0322865)
        (7,-6.9675052)
        (8,-7.9377747)
    };
    \end{axis}
\end{tikzpicture}
\end{document}

which I mostly copied from the pgfplots manual. I want to add small arrows to the $x$ and $y$ axis labels, as in the following plot

example plot

which I made with gnuplot. In gnuplot, I added the small arrows with the aid of TikZ, and I would like to have my pgfplot to have a very similar style (arrows, grid lines etc).

I tried to add the arrows to the axis as follows:

xlabel=\tikz{\draw[>=latex,->,line width=0.2mm] node[left] {Gas / $\mathrm{\frac{kg \cdot J}{m^2}}$} (0,0) -- ++(0.5,0)},

however, that does not work at all. How should I change my code?

1 Answer 1

2

Your proposal nests tikzpictures, which should be avoided. Try

\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\begin{document}
\begin{tikzpicture}
    \begin{axis}[
        grid=both,
        grid style={line width=0.2pt, dashed, color=black},
        xlabel=xlabel, xlabel style={alias=aux},
        ylabel=ylabel,  ylabel style={alias=auy}]
    \addplot[color=red,mark=x] coordinates {
        (2,-2.8559703)
        (3,-3.5301677)
        (4,-4.3050655)
        (5,-5.1413136)
        (6,-6.0322865)
        (7,-6.9675052)
        (8,-7.9377747)
    };
    \end{axis}
    \draw[-latex] (auy.east) -- ++(0,0.5);
    \draw[-latex] ([xshift=1mm]aux.east) -- ++(0.8,0);
\end{tikzpicture}
\end{document}

enter image description here

instead. Please note that, if you rotate the y label, the meaning of east, north etc. will change, you may then do something like \draw[-latex] (aux.north) -- ++(0,0.5); instead. Note also that after the axis is "done", there is the current axis node, whose anchors you many use, as well as xticklabel cs and so on (see section 4.9 of the pgfplots manual).

1
  • yay! this is exactly how I wanted it. Thanks! actually, I don't want to rotate the y axis label - I want all labels to have horizontal text.
    – T. Pluess
    Oct 6, 2018 at 22:23

You must log in to answer this question.

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