我正在尝试使用 pgfplots 从教科书中重现此图表:
我遇到的问题是,我无法找到一种以视觉上吸引人的方式水平拉伸我的 tikzpicture 的方法 - resizebox 无法实现它。
这是我目前所得到的,请原谅它不是最“最小”的,我觉得如果我的“MWE”类似于我试图模仿的图表,那么问题会更容易理解。
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\pgfplotsset{
standard/.style={
axis line style = thick,
trig format=deg,
enlargelimits,
axis x line=middle,
axis y line=middle,
enlarge x limits=0.15,
enlarge y limits=0.15,
every axis x label/.style={at={(current axis.right of origin)},anchor=north west},
every axis y label/.style={at={(current axis.above origin)},anchor=south east}
}
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
standard,
xmin=-4, xmax=10,
xtick={-3.14159*3/2,-3.14159,-3.14159/2,3.14159/2,3.14159,3.14159*3/2,3.14159*2,3.14159*5/2,3.14159*3,3.14159*7/2}, ytick={-1,1},
xticklabels={}, yticklabels={$-1$,$1$},
xlabel={$x$}, ylabel={$y$},]
\addplot[domain=-5:11,samples=300] {cos(deg(x))};
\node[above] at (-3.14159,0) {$-\pi$};
\node[above] at (3.14159,0) {$\pi$};
\node[above] at (3.14159*3,0) {$3\pi$};
\node[below] at (-3.14159/2,0) {$-\frac{\pi}{2}$};
\node[below] at (3.14159/2,0) {$\frac{\pi}{2}$};
\node[below] at (3.14159*3/2,0) {$\frac{3\pi}{2}$};
\node[below] at (3.14159*2,0) {$2\pi$};
\node[below] at (3.14159*5/2,0) {$\frac{5\pi}{2}$};
\end{axis}
\end{tikzpicture}
\end{document}
这将生成一个方形图:
如何才能使我的图表与书中的图表尺寸相同?如何才能在不使用诸如 resizebox 之类的字体破坏操作的情况下水平拉伸它?
非常感谢你的协助!
答案1
您可以更改width
和height
选项pgfplots
:
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\pgfplotsset{
standard/.style={
axis line style = thick,
trig format=deg,
enlargelimits,
axis x line=middle,
axis y line=middle,
enlarge x limits=0.15,
enlarge y limits=0.15,
every axis x label/.style={at={(current axis.right of origin)},anchor=north west},
every axis y label/.style={at={(current axis.above origin)},anchor=south east}
},
width=.96\linewidth,
height=2.5cm,
scale only axis=true
}
\usepackage{lipsum}
\begin{document}
\lipsum[2]
\begin{tikzpicture}
\begin{axis}[
standard,
xmin=-4, xmax=10,
xtick={-3.14159*3/2,-3.14159,-3.14159/2,3.14159/2,3.14159,3.14159*3/2,3.14159*2,3.14159*5/2,3.14159*3,3.14159*7/2}, ytick={-1,1},
xticklabels={}, yticklabels={$-1$,$1$},
xlabel={$x$}, ylabel={$y$},]
\addplot[domain=-5:11,samples=300] {cos(deg(x))};
\node[above] at (-3.14159,0) {$-\pi$};
\node[above] at (3.14159,0) {$\pi$};
\node[above] at (3.14159*3,0) {$3\pi$};
\node[below] at (-3.14159/2,0) {$-\frac{\pi}{2}$};
\node[below] at (3.14159/2,0) {$\frac{\pi}{2}$};
\node[below] at (3.14159*3/2,0) {$\frac{3\pi}{2}$};
\node[below] at (3.14159*2,0) {$2\pi$};
\node[below] at (3.14159*5/2,0) {$\frac{5\pi}{2}$};
\end{axis}
\end{tikzpicture}
\lipsum[2]
\end{document}