[Tex/LaTex] Scale Y and X axis in pgfplots

pgfplots

I made the following plot, and the numbers are print to close together. How can I scale the the y and x axis?

\begin{tikzpicture}
\begin{axis}[
axis y line=center,
axis x line=middle,
axis equal,
grid=both,
xmax=10,xmin=-10,
ymin=-10,ymax=10,
xlabel=$x$,ylabel=$y$,
xtick={-10,...,10},
ytick={-10,...,10},
]

\addplot coordinates{(-3,1) (6,-2)};
\end{axis}
\end{tikzpicture}

Best Answer

pgfplots can adjust the distance between the tick labels as the width/height of the varies. Hence you can change the width (or height) of the plot by passing width = <dimen> to the axis options:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\begin{document}
  \begin{tikzpicture}
\begin{axis}[
width=15cm,               %% here, adjust as suitable
%axis y line=center,
%axis x line=middle,
axis lines = middle,  %% instead of above two lines this one is enough
scaled ticks=false,
axis equal,
grid=major,
xmax=9,xmin=-9,
ymin=-10,ymax=10,
xlabel=$x$,ylabel=$y$,
xtick={-10,...,10},
ytick={-10,...,10},
]

\addplot coordinates{(-3,1) (6,-2)};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

The pdf such generated can be included in the main document using \includegraphics. If you want a uniform width for all the graphs, add it to the \pgfplotsset like

\pgfplotsset{width=15cm}

On ther other hand, you can define a style like

\pgfplotsset{
small/.style={
width=12cm,
height=,
tick label style={font=\tiny},
label style={font=\small},
max space between ticks=35,
}
}

and use it to maintain consistency:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.11}
\pgfplotsset{
small/.style={
width=12cm,
height=,
tick label style={font=\tiny},
label style={font=\small},
max space between ticks=35,
}
}
\begin{document}
  \begin{tikzpicture}
\begin{axis}[
small,             %% here
%axis y line=center,
%axis x line=middle,
axis lines = middle,  %% instead of above two lines this one is enough
scaled ticks=false,
axis equal,
grid=major,
tick label/.style={font=\large},
xmax=9,xmin=-9,
ymin=-10,ymax=10,
xlabel=$x$,ylabel=$y$,
xtick={-10,...,10},
ytick={-10,...,10},
]

\addplot coordinates{(-3,1) (6,-2)};
\end{axis}
\end{tikzpicture}
\end{document}

enter image description here

Refer to section 4.10.2, page 248 of pgfplots manual for more details.

Related Question