我怎样才能使尺寸tikzpicture
与长度成比例axis
?例如,如果我在范围 [0,2*Pi] 和 [0,3*Pi] 上绘制一个函数,我怎样才能使后者比前者宽 1.5 倍?
梅威瑟:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=8cm,compat=1.15}
\begin{document}
\begin{tikzpicture}
\begin{axis}[grid=major]
\addplot [blue] expression [domain=0:2*pi,samples=300] {sin(deg(x))*sin(2*deg(x))};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[grid=major]
\addplot [red] expression [domain=0:3*pi,samples=300] {sin(deg(x))*sin(2*deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% TeX-command-extra-options: "--shell-escape"
%%% End:
更新 1
我的实际问题涉及 3D 绘图,并且评论解决方案中建议的方法/pgfplots/x={<dimen>}
是需要指定所有三个x
,y
,z
这会扰乱我的初始绘图的外观:
MWE 3D:
\documentclass[convert={density=500,outext=.png},border=1mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=8cm,compat=1.15}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
% x=0.08mm,
% y=50mm,
% z=0.01mm,
colorbar horizontal,
colorbar style={
separate axis lines,
at={(0.5,1.03)},anchor=south,
xticklabel pos=upper,
title style={yshift=5 pt},
title={ colorbar title 1}
},
view={0}{90},
xlabel={ x label},
ylabel={ y label},
ymin=1,
extra y ticks={1}, % force 1 to appear among the ticks.
grid=major,
xminorgrids=true,
minor tick num=1,
point meta min=0,
point meta max=16
]
\addplot3 [contour filled={ levels={2,4,6,8,10,12,14,16} }]
table {
150.0000 1.0000 0.0000
200.0000 1.0000 0.0235
250.0000 1.0000 0.3918
300.0000 1.0000 1.5710
350.0000 1.0000 0.1546
400.0000 1.0000 0.3470
450.0000 1.0000 3.3852
500.0000 1.0000 4.2527
550.0000 1.0000 9.2669
600.0000 1.0000 0.0021
650.0000 1.0000 -0.0000
700.0000 1.0000 -0.0000
150.0000 1.5000 -0.0000
200.0000 1.5000 0.2833
250.0000 1.5000 0.0295
300.0000 1.5000 0.1458
350.0000 1.5000 4.2348
400.0000 1.5000 1.9810
450.0000 1.5000 0.9533
500.0000 1.5000 3.5815
550.0000 1.5000 0.0466
600.0000 1.5000 0.0039
650.0000 1.5000 -0.0000
700.0000 1.5000 -0.0000
150.0000 2.0000 0.0000
200.0000 2.0000 0.1007
250.0000 2.0000 0.0020
300.0000 2.0000 0.3198
350.0000 2.0000 1.5419
400.0000 2.0000 9.1226
450.0000 2.0000 9.4154
500.0000 2.0000 2.5719
550.0000 2.0000 -3.1944
600.0000 2.0000 0.0027
650.0000 2.0000 -0.0000
700.0000 2.0000 -0.0000
};
\end{axis}
\end{tikzpicture}
%
\begin{tikzpicture}
\begin{axis}[
colorbar horizontal,
colorbar style={
separate axis lines,
at={(0.5,1.03)},anchor=south,
xticklabel pos=upper,
title style={yshift=5 pt},
title={ colorbar title 2}
},
view={0}{90},
xlabel={ x label},
ymin=1,
extra y ticks={1}, % force 1 to appear among the ticks.
grid=major,
xminorgrids=true,
minor tick num=1,
point meta min=0,
point meta max=16
]
\addplot3 [contour filled={ levels={2,4,6,8,10,12,14,16} }]
table [x expr=\thisrowno{0}*1.5] {
150.0000 1.0000 0.0015
200.0000 1.0000 0.1417
250.0000 1.0000 2.1454
300.0000 1.0000 1.1078
350.0000 1.0000 0.0932
400.0000 1.0000 12.6059
450.0000 1.0000 11.5850
500.0000 1.0000 0.1040
550.0000 1.0000 -0.0001
600.0000 1.0000 -0.0000
650.0000 1.0000 0.0005
700.0000 1.0000 0.0266
150.0000 1.5000 0.0028
200.0000 1.5000 0.3706
250.0000 1.5000 0.0697
300.0000 1.5000 0.4941
350.0000 1.5000 0.0306
400.0000 1.5000 7.6033
450.0000 1.5000 15.6078
500.0000 1.5000 5.2710
550.0000 1.5000 -0.0001
600.0000 1.5000 -0.0000
650.0000 1.5000 -0.0000
700.0000 1.5000 0.0026
150.0000 2.0000 -0.0004
200.0000 2.0000 0.0013
250.0000 2.0000 0.1696
300.0000 2.0000 2.2891
350.0000 2.0000 0.0112
400.0000 2.0000 0.2564
450.0000 2.0000 13.2160
500.0000 2.0000 4.8434
550.0000 2.0000 0.2342
600.0000 2.0000 -0.0000
650.0000 2.0000 -0.0000
700.0000 2.0000 -0.0000
};
\end{axis}
\end{tikzpicture}
\end{document}