I am asking if there is a command in the pgfplots package that changes the appearance of the grid in terms of kind of the lines. What I mean is how to change the kind of lines. I have read the documentation but I could not find anything on this issue.
Asked
Active
Viewed 3.5k times
32
Peter Jansson
- 7,206
Mazzy
- 7,642
1 Answers
49
As with most of the settings in pgfplots, you can set these things globally in the preamble using \pgfplotsset
For example
- minor ticks:
\pgfplotsset{minor grid style={dashed,red}} - major ticks:
\pgfplotsset{major grid style={dotted,green!50!black}} - both minor and major ticks:
\pgfplotsset{grid style={dashed,gray}}
A complete MWE follows

\documentclass{standalone}
\usepackage{pgfplots}
% grid style
\pgfplotsset{grid style={dashed,gray}}
\pgfplotsset{minor grid style={dashed,red}}
\pgfplotsset{major grid style={dotted,green!50!black}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
xtick={-4,-2,...,4},
minor xtick={-5,-3,...,5},
grid=both]
\addplot {x^2};
\end{axis}
\end{tikzpicture}
\end{document}
cmhughes
- 100,947
\addplotdraw the parabola in blue and with the dots? Is that defined in the plot itself outside of this MWE? – Andyc Apr 08 '21 at 11:32pgfplots– cmhughes Apr 08 '21 at 14:00