Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I used ymin=0 and ymax=1000 to give axis the length I want. The problem is that if I have some "crazy" data that escape (I have to plot stable solution vs. unstable solution of my algorithm), pgfplots changes the axis length (data range). How I fix that?

Edit: This is my code:

\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}

And this the content of two files: Data/curiosity_nopar_10s.dat and 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
share|improve this question
    
you can specify width=<somelength> and height=<someotherlength>; does that help? –  cmhughes Sep 23 '12 at 16:28
    
By "axis length", do you mean the data range of the axis (i.e. 1 to 1000), or do you mean the dimensions of the axis (i.e. the plot is 4cm tall)? The axis range should not change if you have provided both ymin and ymax. Could you provide a minimal example document that demonstrates the behaviour? –  Jake Sep 23 '12 at 16:32
    
@Jake I mean the data range of the axis. I edited the question. ;) –  R. M. Sep 23 '12 at 16:33
    
@R.M.: Sorry, I extended my comment after I clicked "send" for the first time: From your description, this is unexpected behaviour. Could you provide a small example document with some dummy data that demonstrates the behaviour you describe? –  Jake Sep 23 '12 at 16:38
    
@Jake Yes, I was surprised too... I will edit the question with my code. –  R. M. Sep 23 '12 at 16:41

1 Answer 1

up vote 2 down vote accepted

This happens because compared to the data range (-2.9e186 to -326), the visible axis range is considered to be too small by PGFPlots, so it tries to find a more useful value. You can avoid this behaviour by explicitly filtering out the data you don't want to plot, using 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}
share|improve this answer
    
So restrict y to domain is like ymin and ymax but stronger? –  R. M. Sep 23 '12 at 17:14
1  
@R.M.: Yes. restrict y to domain actually filters out the coordinates, while ymin and ymax only sets the visible range. –  Jake Sep 23 '12 at 17:16
    
Perfect! Thank you! –  R. M. Sep 23 '12 at 17:17
    
I have a problem. The green line doesn't appear because as you says restrict y to domain is a filter, so only the first point is taken in consideration. In need to see the green line in my figure. Is there any alternative way to do that? Thank you. –  R. M. Sep 23 '12 at 18:24
    
@R.M.: In that case, set restrict y to domain=-5000:5000 or similar, while keeping ymin=0, ymax=5600. –  Jake Sep 27 '12 at 14:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.