Useful pgfplots commands

Set categorical axis labels

\begin{axis}
[
xticklabels={master, g8, lehrer, promovieren, sport, sitzenbleiben},
xtick={1,...,6},
x tick label style={rotate=90,anchor=east}
]
    ...
\end{axis}

Read data from file

The data file needs to be tab-separated. The first column is treated as x-value.

\pgfplotstableread{data.csv}\datatable
\begin{axis}
    \addplot table[y = myColumn] from \datatable;
    \addlegendentry{Results from myColumn};
\end{axis}

 Use percentage as axis label

If the y-values are given in a range of, say, 0.0 to 1.0, the following command displays them as 0% to 100% on the y-axis.

\begin{axis}
[
yticklabel={\pgfmathparse{\tick*100}\pgfmathprintnumber{\pgfmathresult}\%},
]
    ...
\end{axis}

Do not connect data points with lines (scatter plot)

\begin{axis}
[
only marks
]
    ...
\end{axis}

References

  • [1] Plotting experimental data with pgfplots by Josef Wright (TUGboat, Volume 31 (2010), No. 1)
  • [2] Official pgfplots gallery

Leave a Reply