5
$\begingroup$

Mathematica 12 introduces built-in plotting support for data with errorbars.

The following example looks good with the default settings:

ListPlot[Table[Around[i, 5], {i, 10}]]

Correct plot range

However, when I set PlotRange->All, the error bars get cropped:

ListPlot[Table[Around[i, 5], {i, 10}], PlotRange -> All]

Cropped error bars

Here is an example, where default PlotRange crops error bars:

ListPlot[{Table[{i, Around[1/i, {-10, 10}]}, {i, -5.5, 5.5, 1.0}], 
          Table[{i, 3 i}, {i, 0.5, 5.5, 1.0}]}]

Cropped error bars

and adding PlotRange->All does not help either:

ListPlot[{Table[{i, Around[1/i, {-10, 10}]}, {i, -5.5, 5.5, 1.0}], 
          Table[{i, 3 i}, {i, 0.5, 5.5, 1.0}]}, 
         PlotRange -> All]

Cropped error bars

Is there a universal option to get the full PlotRange for any data with error bars?

$\endgroup$
8
$\begingroup$

A work-around: use Show with the option PlotRange -> All:

Show[ListPlot[Table[Around[i, 5], {i, 10}]], PlotRange -> All]

enter image description here

Show[ListPlot[{Table[{i, Around[1/i, {-10, 10}]}, {i, -5.5, 5.5, 1.0}], 
      Table[{i, 3 i}, {i, 0.5, 5.5, 1.0}]}], PlotRange -> All]

enter image description here

An alternative work-around is to use explicit range for the vertical axis:

tbl = Table[Around[i, 5], {i, 10}];
yrange = MinMax[#["Interval"]& /@ tbl];
ListPlot[tbl, PlotRange -> {Automatic, yrange}]

enter image description here

For the second example:

tbl2 = {Table[{i, Around[1/i, {-10, 10}]}, {i, -5.5, 5.5, 1.0}], 
        Table[{i, 3 i}, {i, 0.5, 5.5, 1.0}]};
yrange2 = MinMax @ Flatten[tbl2[[All, All, 2]] /. a_Around :> MinMax[ a["Interval"]]];
ListPlot[tbl2, PlotRange -> {Automatic, yrange2}]

enter image description here

$\endgroup$
3
$\begingroup$

It seems that if one replaces the PlotRange option in the resulting graphics expression by PlotRange->All, all works out. The resulting Graphics from

ListPlot[Table[Around[i, 5], {i, 10}],PlotRange -> All]

(if one inspects it via InputForm) has an explicit set of plot ranges

PlotRange -> {{0.8125000000000003, 10.}, {0, 10.}}

But replacing that with PlotRange->All explicitly the wished-for graphic is obtained

ListPlot[Table[Around[i, 5], {i, 10}],
    PlotRange -> All] /. (PlotRange -> _) :> (PlotRange -> All)

This seems to be a bug. For example if one evaluates a simple plot

Plot[x, {x, 0, 5}, PlotRange -> All] // InputForm

the PlotRange is

PlotRange -> {All, All}

and has not been transformed into an explicit numerical PlotRange. I will send in a bug report and see what the response is.

$\endgroup$
  • $\begingroup$ In your final example of a simple plot, try usual procedure: PlotRange[Plot[x, {x, 0, 5}, PlotRange -> All]] and you will get explicit numerical intervals (without taking PlotRangePadding into account). And I think your variant with further replacing PlotRange is essentially what Show does. Nevertheless, very useful observations, +1. $\endgroup$ – Alx Aug 3 at 11:59
  • $\begingroup$ Hi Alx, Cases[Plot[x,{x,0,5},PlotRange->All],z:(PlotRange->_):>z,Infinity] gives {PlotRange->{All,All}} and not an explicit numerical interval. Perhaps I misunderstood the first part of your comment though. BTW I checked with WRI bugs and submitted this -- it is likely related to a known bug that they are aware of. $\endgroup$ – David Reiss Aug 3 at 17:18
  • $\begingroup$ I only meant that ususal way to know plotrange is PlotRange[<your Plot command here>] or undocumented get2DPlotRange from Charting context. $\endgroup$ – Alx Aug 3 at 23:57
  • $\begingroup$ Ah, I didn't read your comment carefully enough! My appologies Alx. $\endgroup$ – David Reiss Aug 4 at 21:31

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.