9
$\begingroup$

Bug introduced in 8.0 or earlier and persisting through 13.0.0 or later


How to disable rounding up the radius which is used to calculate the origin of the polar axes with the option PolarAxesOrigin? Example:

PolarPlot[Sqrt[n], {n, 0, 20}, PolarAxes -> True,
PolarAxesOrigin -> {0, 7}, PolarTicks -> {"Degrees", Automatic}]

polar plot

It rounds 7 to 8, 13 to 15 and 521 to 600.

$\endgroup$
5
  • $\begingroup$ Added the bugs tag. Feel free to remove it if I made a mistake $\endgroup$ Dec 19, 2013 at 21:29
  • $\begingroup$ Should I report it to customer support? $\endgroup$
    – shrx
    Dec 19, 2013 at 21:31
  • $\begingroup$ I'd suggest waiting for a day or o to see if someone else can find a workaround $\endgroup$ Dec 19, 2013 at 21:50
  • $\begingroup$ @shrx I have added the bug header. Is the introduction version correct? I don't have access to earlier version than 9.0 at the moment. $\endgroup$
    – user31159
    Oct 8, 2016 at 12:03
  • $\begingroup$ @Xavier thanks for the edit. I also don't have old versions installed anymore, but you can judge from the date the question was posted here which version was used. $\endgroup$
    – shrx
    Oct 10, 2016 at 6:55

4 Answers 4

6
$\begingroup$

It seems like PolarPlot uses FindDivisions internally to generate the ticks and chooses the last point as the origin, which causes this behaviour:

FindDivisions[{0, 7}, 4]
(* {0, 2, 4, 6, 8} *)

This is in fact described in the documentation for FindDivisions (under "Details and Options"):

The first and last numbers may be slightly outside the range $x_\min$ to $x_\max$

I've run into similar subtle quirks with PolarPlot – especially when styling/customizing it a particular way — and usually end up writing my own version of PolarPlot using graphics primitives.

$\endgroup$
4
$\begingroup$

The simplest workaround:

PolarPlot[Sqrt[n], {n, 0, 20}, PolarAxes -> {True, False}, 
 PolarAxesOrigin -> {0, 7}, PolarTicks -> {"Degrees", Automatic}, 
 Axes -> {True, False}]

enter image description here

$\endgroup$
1
  • $\begingroup$ Thanks, I could almost use this, I just need to figure out how to perform Abs[] on major ticks while preserving the minor ticks, and how to cut off the axes at [-7,7]. Will look into it now. $\endgroup$
    – shrx
    Dec 29, 2013 at 21:09
2
$\begingroup$

I have contacted Technical Support and they have confirmed this to be a bug. They have also provided the following workaround:

plot = PolarPlot[7 Sin[x], {x, 0, 2 Pi}, PolarAxesOrigin -> {0, 7}, 
PolarAxes -> True]

initial plot

(* Rescale the circular part. *)
plot[[1, 5, 1]] = Scale[plot[[1, 5, 1]], {7/8, 7/8}];

(* Remove the tick "8". *)
Cases[plot[[1, 5, 2]], Text[___], Infinity]
{Text[0., Offset[{0, -8}, Scaled[{0., -0.006}, {0, 0}]], {-1, 0}], 
Text[2., Offset[{0, -8}, Scaled[{0., -0.006}, {2, 0}]], {-1, 0}], 
Text[4., Offset[{0, -8}, Scaled[{0., -0.006}, {4, 0}]], {-1, 0}], 
Text[6., Offset[{0, -8}, Scaled[{0., -0.006}, {6, 0}]], {-1, 0}], 
Text[8., Offset[{0, -8}, Scaled[{0., -0.006}, {8, 0}]], {-1, 0}]}
Position[plot[[1, 5, 2]], Text[___], Infinity]
{{4, 1}, {4, 2}, {4, 3}, {4, 4}, {4, 5}}
plot[[1, 5, 2]] = Delete[plot[[1, 5, 2]], {{4, 5}}];
plot

plot with fixed origin

$\endgroup$
1
$\begingroup$

We can use the function fixPolarAxes from this answer to post-process PolarPlot output to fix polar axes/ticks/gridlines:

plot = PolarPlot[7 Sin[x], {x, 0, 2 Pi},
  PolarAxesOrigin -> {0, 7}, PolarAxes -> True]

enter image description here

fixPolarAxes[7] @ plot

enter image description here

ClearAll[fixPolarAxes]

fixPolarAxes[radius_] := 
  Module[{maxradius = Max @ Cases[#, Circle[_, r_, _] :> r, All], scale},
   scale = radius / maxradius;
   ReplaceAll[
    {Circle[c_, maxradius, a_] :> Circle[c, radius, a] (* change angular axis radius *),
     Circle[_, r_/; r > radius,_] -> {} (* remove unwanted radial gridlines *),
     Text[_, Offset[_, Scaled[_, a_ /; Norm[a] > radius]], ___] -> 
           {} (* remove unwanted radial tick labels *),
     Style[Line[{Scaled[_, a_], _Scaled}] /; Norm[a] > radius, Except[{}]] -> 
           {} (* remove unwanted radial ticks *),
     Text[t_, Offset[a_, b : Except[_Scaled]], c___] :> 
          Text[t, Offset[a, scale b], c] (* move angular labels towards new axis*),
     Line[{{0, 0}, a : {_, _}}] :>
       Line[{{0, 0}, scale a}] (* crop the radial axis and angular gridlines *),
     Style[Line[x_], {}] :>
      {Line[x /. { {{a_, b_}, Scaled[c_, d_]} :> 
          {scale {a, b}, Scaled[c, scale d]} (* relocate minor angular ticks *),
      Scaled[a_, b_] :> Scaled[a, scale b] (* relocate major angular ticks *)}]}}] @ #]&
$\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.