I am currently having an issue with ListPolarPlot, specifically with achieving a consistent size among multiple plots. Consider the following illustration of my issues:

(* some common options for the plots *)
opts = {PolarAxes -> True, PlotRangePadding -> Scaled@0.12, ImageSize -> 350};

tests[pr_] := {
  ListPolarPlot[Table[{i, (Cos@i)^2}, {i, 0, 2 π, π/10}], PlotRange -> pr, opts],
  ListPolarPlot[Table[{i, 1.26 (Cos@i)^2}, {i, 0, 2 π, π/10}], PlotRange -> pr, opts],
  ListPolarPlot[Table[{i, (Cos@i)^10}, {i, 0, 2 π, π/500}], PlotRange -> pr, opts]

tests /@ {All, Automatic, Full}

enter image description here

Note how neither of the option values produces consistent results: All is broken for the middle plot, Automatic for the last one, and let's not even talk about Full...

Is there any way to get sizing consistent, without resorting to manual adjustments?


The following fixes the problem by changing the definition of ListPolarPlot:

 DownValues[listPolarPlot] = DownValues[listPolarPlot] /.
   expr : HoldPattern[allPos = _] :> 
     (expr; maxRadius = Max[maxRadius, layoutData@"RadialAxesRadius"]);
 $FixedPolarPlots = False;


enter image description here

What does this do

To understand why this works, we first notice that PlotRange->All is pretty close to what we need, it just has issues for the middle plot. Looking at the PlotRange specified for the resulting three plots gives the following:

Options[#, PlotRange] & /@ tests[All]
(* {
     {PlotRange -> {{-1., 1.}, {-1., 1.}}},
     {PlotRange -> {{-1.26, 1.26}, {-1.26, 1.26}}},
     {PlotRange -> {{-1., 1.}, {-1., 1.}}}
   } *)

Note how the PlotRange in the middle plot is based only on the data (with a max value of 1.26), whereas the radial axis of the plot goes up to 1.5, presumably because it's a nicer number. The fix is now easy: We simply need to adjust the PlotRange by the range of the radial axis if necessary, to ensure that the plot always shows at least the polar axes.

And this is exactly what the code above does: It inserts a single line into the code that adjusts maxRadius (used to compute absolute values PlotRange->All) to be at least as big as layoutData@"RadialAxesRadius", which is set to the range of the radial axis (or 0 if none is drawn).


Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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