How can I generate and randomly assign color to annular sectors?
Hmm...Szabolcs beat me to it (in a comment) by one minute...
plot = ParametricPlot[r {Cos[t], Sin[t]}, {r, 0, 12}, {t, 0, 2 Pi},
Mesh -> 23, Axes -> False,
MeshShading -> {{Red, Green}, {Blue, Yellow}},
PlotRange -> {{-9, 9}, {-4, 4}}];
plot /. poly_Polygon :> {RGBColor @@ RandomReal[1, 3], poly}
With V10 came RandomColor
and ColorSpace
Using Michael E2's wonderful solution
plot =
ParametricPlot[r {Cos[t], Sin[t]}, {r, 0, 12}, {t, 0, 2 Pi},
ImageSize -> 500,
Mesh -> 13,
MeshShading -> {{Red, Red}, {Red, Red}},
PlotRange -> {{-9, 9}, {-4, 4}}];
Grid @ Partition[Table[plot /.
poly_Polygon :> {RandomColor[ColorSpace -> space], poly},
{space, {"RGB", "XYZ", "CMYK", "Grayscale"}}], 2]
Making the MeshShading
setting Dynamic
also works without the need for post-processing:
ParametricPlot[r {Cos[t], Sin[t]}, {r, 0, 12}, {t, 0, 2 Pi},
Mesh -> 23, Axes -> False,
MeshShading -> Dynamic@{{Hue@RandomReal[], Hue@RandomReal[]},
{Hue@RandomReal[], Hue@RandomReal[]}},
PlotRange -> {{-9, 9}, {-4, 4}}]
The same trick works in combination with V10 RandomColor
:
ParametricPlot[r {Cos[t], Sin[t]}, {r, 0, 12}, {t, 0, 2 Pi},
Mesh -> 23, Axes -> False,BaseStyle->Opacity[.75],
MeshShading ->Dynamic@ {{RandomColor[], RandomColor[]},
{RandomColor[], RandomColor[]}},
PlotRange -> {{-9, 9}, {-4, 4}}]
ParametricPlot[r {Cos[t], Sin[t]}, {r, 0, 12}, {t, 0, 2 Pi},
Mesh ->{25,25}, Axes -> False, BaseStyle->Opacity[.75],
MeshShading ->Dynamic@Evaluate@ Table[RandomColor[],{25},{2}],
PlotRange -> {{-9, 9}, {-4, 4}}]
ParametricPlot[r {Cos[t], Sin[t]}, {r, 0, 12}, {t, 0, 2 Pi},
Mesh ->{25,25}, Axes -> False, BaseStyle->Opacity[.75],
MeshShading ->Dynamic@Evaluate@ Table[RandomColor[],{2},{25}],
PlotRange -> {{-9, 9}, {-4, 4}}]