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?
You can use ParametricPlot
to get the sector.
plot = PolarPlot[1 + 1/10 Sin[10 t], {t, 0, 2 Pi}]
sectorShade = ParametricPlot[
r (1 + 1/10 Sin[10 t]) {Cos[t], Sin[t]},
{t, 0, Pi/4},
{r, 0, 1}
] /. Line -> Polygon
Show[plot, sectorShade, PlotRange -> All]
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:
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
-
$\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 theBoundaryStyle
option that should be used. I added an example to the answer. The default color is given byColorData[97, 1]
. If you'd had more curves, they'd useColorData[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
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]}]
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] }]
Update: If you have to get the result using PolarPlot
only, you can make two PolarPlot
s 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]])]
-
$\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