6

Further to the accepted answer to this question: Retrieving PlotRange from BarChart, how can this be done in version 11?

In version 7 it worked like this.

enter image description here

In version 11 it doesn't work.

enter image description here

Code for copy & paste

bc = BarChart[{1, 2, 3, 4}, PerformanceGoal -> "Speed"];
Options[bc, PlotRange]
AbsoluteOptions[bc, PlotRange]

Further to J.M.'s comment Charting`get2DPlotRange[] is not a perfect replacement for AbsoluteOptions although it is of some use.

Here is a more complex example for illustration:

vals = {37.0186, 40.9317, -56.0248, -21.9255};
{vmin, vmax} = Through[{Min, Max}[vals]];
interval = If[Max[0, vmax] - Min[0, vmin] > 50, 20, 10];
frameticks = {#, #, {0, 0.01}} & /@ ((Range[21] - 11)*interval);
f[l_, p_, r_] := BarChart[vals, LabelingFunction -> (Placed[Round[#1],
       If[Round[#1] < 1, l, After]] &), BarOrigin -> Left,
   BarSpacing -> 0.8, PlotRangePadding -> {interval, p},
   Frame -> {{False, False}, {True, False}}, Ticks -> None,
   FrameTicks -> {{None, None}, {frameticks, None}},
   PerformanceGoal -> "Speed", PlotRange -> {All, r}];

in Version 7

Print[chart = f[Right, 0.4, {0, 6.4}]];
PlotRange /. AbsoluteOptions[chart, PlotRange]

{{-56.0248, 40.9317}, {0., 6.4}}

in Version 11

chart = f[Before, 0, {0.5, 4.5}];
Print[Show[chart,
   Graphics[{GrayLevel[0.3], AbsoluteThickness[0.25],
     Style[Line[{{0, 0.5}, {0, 4.5}}], Antialiasing -> False]}]]];
Charting`get2DPlotRange[chart]

{{-76.0248, 60.9317}, {0.722222, 4.27778}}

However, further to rcollyer's comment

Charting`get2DPlotRange[chart, False]

{{-56.0248, 40.9317}, {0.722222, 4.27778}}

The x minimum and maximum match version 7.

Chris Degnen
  • 30,927
  • 2
  • 54
  • 108

1 Answers1

3

You could use my function graphicsInformation to do this:

bc=BarChart[{1,2,3,4},PerformanceGoal->"Speed"];
"PlotRange" /. graphicsInformation[bc]

{{-0.0840242, 5.09461}, {-0.0860215, 4.21505}}

For your other examples:

"PlotRange" /. graphicsInformation[f[Right, 0.4, {0, 6.4}]]
"PlotRange" /. graphicsInformation[f[Before,0,{0.5,4.5}]]

{{-76.0248, 60.9317}, {-0.4, 6.8}}

{{-76.0248, 60.9317}, {0.5, 4.5}}

Carl Woll
  • 130,679
  • 6
  • 243
  • 355