2
$\begingroup$

This explains how to shade a region between two polar graphs. Unfortunately my mathematica-fu is too weak to see how it would be used to shade one sector of a single polar graph. Any suggestions, please?

$\endgroup$
4
$\begingroup$

You can use ParametricPlot to get the sector.

plot = PolarPlot[1 + 1/10 Sin[10 t], {t, 0, 2 Pi}]

Mathematica graphics

sectorShade = ParametricPlot[
   r (1 + 1/10 Sin[10 t]) {Cos[t], Sin[t]},
   {t, 0, Pi/4},
   {r, 0, 1}
   ] /. Line -> Polygon

Mathematica graphics

Show[plot, sectorShade, PlotRange -> All]

Mathematica graphics

The Line -> Polygon trick is needed for the color to be solid. Otherwise, the sector will look like this when combined with the polar plot:

Mathematica graphics

You can set the style of the sector using BoundaryStyle:

sectorShade = ParametricPlot[
   r (1 + 1/10 Sin[10 t]) {Cos[t], Sin[t]},
   {t, 0, Pi/4},
   {r, 0, 1},
   BoundaryStyle -> ColorData[97, 2]
   ] /. Line -> Polygon

Mathematica graphics

$\endgroup$
  • $\begingroup$ Thank you for the detailed explanation. Only one question; where do you set color? Is there a system default? If so, where is it set? How do you override? $\endgroup$ – jamesson Jul 13 '17 at 17:14
  • $\begingroup$ @jamesson Good question, this is not obvious because of the Line -> Polygon trick. It is the BoundaryStyle option that should be used. I added an example to the answer. The default color is given by ColorData[97, 1]. If you'd had more curves, they'd use ColorData[97, 2], ColorData[97, 3] and so on. You can set the default using $PlotTheme (this variable is documented.) There is an answer about creating a custom plot theme here. $\endgroup$ – C. E. Jul 13 '17 at 18:30
2
$\begingroup$

You can also use a single ParametricPlot with two functions as the first argument:

ParametricPlot[{r (1 + 1/10 Sin[10 t]) {Cos[t], Sin[t]}, 
  ConditionalExpression[r (1 + 1/10 Sin[10 t]) {Cos[t], Sin[t]}, 0 <= t <= Pi/4]}, 
 {t, 0, 2 Pi}, {r, 0, 1}, 
 PlotPoints -> 100, Mesh -> None, Frame-> False, PlotStyle -> {None, Opacity[1, Red]}]

enter image description here

Alternatively, use a single function with the options MeshFunctions, Mesh and MeshShading:

ParametricPlot[r (1 + 1/10 Sin[10 t]) {Cos[t], Sin[t]}, 
 {t, 0, 2 Pi}, {r, 0, 1}, 
 PlotPoints -> 100, Frame -> False, 
 MeshFunctions -> {#3 &}, Mesh -> {{0, Pi/4}}, MeshShading -> {None, Opacity[1, Red] }]

enter image description here

Update: If you have to get the result using PolarPlot only, you can make two PolarPlots with different angle ranges and use one of them as the Prolog or Epilog to the other.

PolarPlot[1 + 1/10 Sin[10 t], {t, 0, 2 Pi}, Mesh -> None, 
 Prolog -> (PolarPlot[1 + 1/10 Sin[10 t], {t, 0, Pi/4}, 
      PlotStyle -> Red][[1]] /. Line[x_] :> Polygon[Join[{{0, 0}}, x]])]

[1]: https://i.stack.imgur.com/jws

$\endgroup$
  • $\begingroup$ now if you could only put center axes on that last one! $\endgroup$ – jamesson Jul 14 '17 at 5:27
  • $\begingroup$ Thanks so much, but seems there is a typo (bracket/paren) in that last one, which I cannot find by myself. At least, in 10_4 it will not evaluate as written. $\endgroup$ – jamesson Jul 14 '17 at 18:05
  • $\begingroup$ @jamesson, it works both in version 9 and 11. It could be some version10 glitch. What error message are you getting in 10_4? $\endgroup$ – kglr Jul 14 '17 at 18:11
  • $\begingroup$ As it sits, no error message, just red highlighting on one paren and one bracket. Shall I check which? $\endgroup$ – jamesson Jul 14 '17 at 18:18
  • $\begingroup$ @jamesson, could be an invisible line break somewhere stuck in when you cut/paste code. $\endgroup$ – kglr Jul 14 '17 at 18:23

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.