6
$\begingroup$

Persisting through 11.3, fixed in Mathematica 12.0

We generally use PlotRange->All to see all available points in a plot. But how do you use PlotRange when you want to run it with functions like the below without facing any data clippings.

This is best explained with a MWE:

data = {{1, 0.542399}, {2, 1.45729}, {3, 1.38588}, {4, 1.29452}, {5, 
  3.59352}, {6, 3.6808}, {7, 5.92152}, {8, 0.780593}, {9, 
  7.91613}, {10, 5.2081}};

Plot#1: general usage

ListLinePlot[data, 
 Epilog -> {Green, Line[data], PointSize[Medium], Red, Point[data]}, 
 InterpolationOrder -> 2, PlotRange -> All, GridLines -> Automatic]

1

Plot#2: Manually defined limits for x and y axis

ListLinePlot[data, 
 Epilog -> {Green, Line[data], PointSize[Medium], Red, Point[data]}, 
 InterpolationOrder -> 2, PlotRange -> {{1, 10}, {0.1, 10}}, 
 GridLines -> Automatic]

2

$\endgroup$
4
  • $\begingroup$ a simpler MWE ListLinePlot[data, InterpolationOrder -> 2, PlotRange->All] $\endgroup$
    – kglr
    Nov 1 '18 at 17:50
  • 3
    $\begingroup$ Looks like a glitch introduced in v10 or later (the issue doesn't arise in version 9 -windows 10). $\endgroup$
    – kglr
    Nov 1 '18 at 17:52
  • $\begingroup$ @kglr Damn! Looks like I have a knack to just find glitches. Or whatever I want happens to be a glitch. $\endgroup$ Nov 1 '18 at 20:08
  • $\begingroup$ Certainly a bug in ListPlot, please report it to the support. $\endgroup$ Nov 2 '18 at 8:45
2
$\begingroup$

Clipping has nothing to do with the interpolation: PlotRange is defined based on the plotted data which in this case does not involve interpolated datapoints. I'm not sure if this is a bug or a feature: the displayed spline is obviously not sampled to find its extrema, but this could be by design. Furthermore (not really relevant here, but important) if you include anything in the Epilog or Prolog, those are also not used when calculating PlotRange.

I suggest using an explicit PlotRange, but you can also incorporate the linear and splined functions in one plot:

data = {{1, 0.542399}, {2, 1.45729}, {3, 1.38588}, {4, 1.29452},
        {5, 3.59352}, {6, 3.6808}, {7, 5.92152}, {8, 0.780593},
        {9, 7.91613}, {10, 5.2081}};
Plot[{
  Interpolation[data, InterpolationOrder -> 1][t],
  Interpolation[data, InterpolationOrder -> 2, Method -> "Spline"][t]
  }, {t, 1, 10}, PlotRange -> All, Epilog -> {Red, Point@data}]

Mathematica graphics

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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