我制作了以下图表,数字打印得太近了。如何缩放 y 轴和 x 轴?
\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}
答案1
pgfplots
可以随着宽度/高度的变化调整刻度标签之间的距离。因此,您可以通过传递width = <dimen>
轴选项来更改绘图的宽度(或高度):
\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}
这样生成的 pdf 可以使用 包含在主文档中\includegraphics
。如果您希望所有图表的宽度统一,请将其添加到\pgfplotsset
类似
\pgfplotsset{width=15cm}
另一方面,你可以定义一个类似的风格
\pgfplotsset{
small/.style={
width=12cm,
height=,
tick label style={font=\tiny},
label style={font=\small},
max space between ticks=35,
}
}
并使用它来保持一致性:
\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}
pgfplots
有关更多详细信息,请参阅手册第 248 页第 4.10.2 节。
答案2
使用 PSTricks 的解决方案非常有趣。
\documentclass[pstricks,border=15pt,12pt]{standalone}
\usepackage{pst-plot}
\begin{document}
\begin{psgraph}[Dx=2,Dy=2]{->}(0,0)(-10,-10)(10,10){18cm}{12cm}
\psline[linecolor=blue]{*-*}(-3,3)(5,-3)
\end{psgraph}
\end{document}