我使用ymin=0
和ymax=1000
来为轴指定我想要的长度。问题是,如果我有一些“疯狂”的数据逃逸(我必须绘制算法的稳定解与不稳定解),pgfplots 会自动更改轴长度(数据范围)。我该如何解决这个问题?
编辑: 这是我的代码:
\usepackage{pgfplots}
\pgfplotsset{%
compat=newest,%
/pgf/number format/use comma,%
/pgf/number format/1000 sep={\,},%
/pgf/number format/min exponent for 1000 sep=4}
\begin{document}
% Figure
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[xmin=0,xmax=300,ymin=0,ymax=5600,title={Simulation sans parachute},%
xlabel=Temps (\si{\second}), ylabel=Vitesse (\si{\meter\second^{-1}}),%
legend cell align=left]
\addplot[yellow,thick]
file {Data/curiosity_nopar_10s.dat};
\addplot[green,thick]
file {Data/curiosity_nopar_20s.dat};
\legend{Eq. \eqref{eq:sol}, \(\tau=\SI{0.1}{\second}\), \(\tau=\SI{1}{\second}\), \(\tau=\SI{10}{\second}\), \(\tau=\SI{20}{\second}\)}
\end{axis}
\end{tikzpicture}
\caption[Simulation sans parachute]{Simulation de la descente de la sonde Curiosity sans parachute. Différents pas de temps \( \tau \) sont utilisés pour confronter les résultats numériques avec la solution analytique.}
\end{figure}
% Figure
\end{document}
这是两个文件的内容:Data/curiosity_nopar_10s.dat 和 curiosity_nopar_20s.dat:
0 5500 227000
10 2586.7777285496 201132.2227145
20 1971.254834228 181419.67437222
30 1629.363201817 165126.04235405
40 1407.5346833953 151050.6955201
50 1251.4101402558 138536.59411754
60 1135.7734349219 127178.85976832
70 1047.0598631601 116708.26113672
80 977.23293190282 106935.9318177
90 921.19206699139 97724.011147781
100 875.52749808118 88968.73616697
110 837.86502481312 80590.085918838
120 806.49630581412 72525.122860697
130 780.15839915766 64723.53886912
140 757.89624456155 57144.576423505
150 738.97360219555 49754.84040155
160 722.81350825764 42526.705318973
170 708.95735921594 35437.131726814
180 697.03611739943 28466.77055282
190 686.74961630763 21599.274389743
200 677.85140652233 14820.76032452
210 670.13747132868 8119.3856112332
220 663.43769589269 1485.0086523064
230 657.6093290226 -5091.0846379197
0 5500 227000
20 -326.44454290086 233528.89085802
40 -1833.9424425888 270207.73970979
60 -51679.919240166 1303806.1245131
80 -39692949.188774 795162789.9
100 -23384720610291 4.676952073686e+14
120 -8.1165054198238e+24 1.6233010839694e+26
140 -9.7778389084672e+47 1.9555677816934e+49
160 -1.4190263754218e+94 2.8380527508437e+95
180 -2.9887228740931e+186 5.9774457481862e+187
200 -inf inf
220 -inf inf
240 -inf inf
260 -inf inf
280 -inf inf
300 -inf inf
320 -inf inf
340 -inf inf
360 -inf inf
380 -inf inf
400 -inf inf
420 -inf inf
440 -inf inf
460 -inf inf
480 -inf inf
500 -inf inf
520 -inf inf
540 -inf inf
560 -inf inf
580 -inf inf
600 -inf inf
620 -inf inf
640 -inf inf
660 -inf inf
680 -inf inf
700 -inf inf
720 -inf inf
740 -inf inf
760 -inf inf
780 -inf inf
800 -inf inf
820 -inf inf
840 -inf inf
860 -inf inf
880 -inf inf
900 -inf inf
920 -inf inf
940 -inf inf
960 -inf inf
980 -inf inf
1000 -inf inf
答案1
发生这种情况的原因是,与数据范围(-2.9e186 到 -326)相比,PGFPlots 认为可见轴范围太小,因此它会尝试找到更有用的值。您可以通过使用以下方法明确过滤掉您不想绘制的数据来避免此行为restrict y to domain=0:5600
:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=0,xmax=300,ymin=0,ymax=5600,restrict y to domain=0:5600]
\addplot[yellow,thick]
table {
0 5500 227000
10 2586.7777285496 201132.2227145
20 1971.254834228 181419.67437222
30 1629.363201817 165126.04235405
40 1407.5346833953 151050.6955201
50 1251.4101402558 138536.59411754
60 1135.7734349219 127178.85976832
70 1047.0598631601 116708.26113672
80 977.23293190282 106935.9318177
90 921.19206699139 97724.011147781
100 875.52749808118 88968.73616697
110 837.86502481312 80590.085918838
120 806.49630581412 72525.122860697
130 780.15839915766 64723.53886912
140 757.89624456155 57144.576423505
150 738.97360219555 49754.84040155
160 722.81350825764 42526.705318973
170 708.95735921594 35437.131726814
180 697.03611739943 28466.77055282
190 686.74961630763 21599.274389743
200 677.85140652233 14820.76032452
210 670.13747132868 8119.3856112332
220 663.43769589269 1485.0086523064
230 657.6093290226 -5091.0846379197
};
\addplot[green,thick]
table {
0 5500 227000
20 -326.44454290086 233528.89085802
40 -1833.9424425888 270207.73970979
60 -51679.919240166 1303806.1245131
80 -39692949.188774 795162789.9
100 -23384720610291 4.676952073686e+14
120 -8.1165054198238e+24 1.6233010839694e+26
140 -9.7778389084672e+47 1.9555677816934e+49
160 -1.4190263754218e+94 2.8380527508437e+95
180 -2.9887228740931e+186 5.9774457481862e+187
200 -inf inf
220 -inf inf
240 -inf inf
260 -inf inf
280 -inf inf
300 -inf inf
320 -inf inf
340 -inf inf
360 -inf inf
380 -inf inf
400 -inf inf
420 -inf inf
440 -inf inf
460 -inf inf
480 -inf inf
500 -inf inf
520 -inf inf
540 -inf inf
560 -inf inf
580 -inf inf
600 -inf inf
620 -inf inf
640 -inf inf
660 -inf inf
680 -inf inf
700 -inf inf
720 -inf inf
740 -inf inf
760 -inf inf
780 -inf inf
800 -inf inf
820 -inf inf
840 -inf inf
860 -inf inf
880 -inf inf
900 -inf inf
920 -inf inf
940 -inf inf
960 -inf inf
980 -inf inf
1000 -inf inf
};
\end{axis}
\end{tikzpicture}
\end{document}