I am trying to visually compare multiple functions that depend on a single argument running from $0$ to $1$. They describe a radial property and so I thought it would be nice to use a kind of PieChart
plot where the function values are used as a color function to fill the pie. The best I could come up with is the following:
SectorPlot[func_List, label_List, colorrange_: {0, 66.7},
opts : OptionsPattern[]] /; Length[func] == Length[label] :=
Module[{div, len, sectors, size, wedge, colorbar},
len = Length[func];
sectors = makesectors[len];
size = 300;
colorbar[colorFunction_: Automatic, range_: colorrange, divs_: 25] :=
DensityPlot[y, {x, 0, .1}, {y, First@range, Last@range},
(* Remove possible PlotRange specification from the options,
which would mess up the bar*)
Evaluate[
FilterRules[{opts},
Cases[Options[DensityPlot], Except[PlotRange -> _]]]],
AspectRatio -> 10,
PlotRangePadding -> 0,
PlotPoints -> {2, divs},
MaxRecursion -> 0,
FrameTicks -> {None, Automatic, None, None},
ColorFunctionScaling -> False,
ColorFunction -> colorFunction];
(* now the pie function*)
wedge[fun_, {minangle_, maxangle_}, lab_] := Show[{
ParametricPlot[{v Cos[u], v Sin[u]}, {u, minangle, maxangle}, {v,
0, 1},
Evaluate[FilterRules[{opts}, Options[ParametricPlot]]],
ColorFunction -> (ColorData[{"Rainbow", colorrange}][fun[#4]] &),
ColorFunctionScaling -> False,
Mesh -> False,
ImagePadding -> All,
BoundaryStyle -> Directive[Thick, Black],
Frame -> False,
Axes -> False,
PlotRange -> {-1.2, 1.2},
Background -> Transparent],
Graphics@Text[
Style[lab, Bold, FontFamily -> "Times"], {
1.1 Cos[Mean[{minangle, maxangle}]],
1.1 Sin[Mean[{minangle, maxangle}]]},
{
-Cos[Mean[{minangle, maxangle}]],
-Sin[Mean[{minangle, maxangle}]]}
]}];
Row[{
Show[Table[
wedge[func[[i]], sectors[[i]], label[[i]]], {i, 1, len}],
ImageSize -> {Automatic, size},
ImagePadding -> 20],
Show[colorbar[ColorData[{"Rainbow", colorrange}], colorrange],
ImageSize -> {Automatic, size},
ImagePadding -> 20]}]]
I used the answers to this post to set up the colorbar in a Row
.
Here is an example.
SectorPlot[{
(60 Sin[4.3 # + 0.3]) &,
(50 Sin[12 # + 0.1]) &,
(66 Cos[7.3 # + 0.3]) &,
(60 Tan[1.2 #]) &,
(60 Cos[23.5 # - 0.1]) &},
{"1", "2", "3", "4", "5"}, {0, 70},
BoundaryStyle -> Directive[Thick, Darker@Gray],
PlotRange -> {-1.2, 1.2}]
Everything looks OK, but it looks like a lot of effort given the fact that we have very powerful PieChart
functionalities. Imagine I have to provide longer labels:
SectorPlot[{
(60 Sin[4.3 # + 0.3]) &,
(50 Sin[12 # + 0.1]) &,
(66 Cos[7.3 # + 0.3]) &,
(60 Tan[1.2 #]) &,
(60 Cos[23.5 # - 0.1]) &},
{"12345678901234567890", "12345678901234567890",
"12345678901234567890", "12345678901234567890",
"12345678901234567890"}, {0, 70},
BoundaryStyle -> Directive[Thick, Darker@Gray], PlotRange -> {-2, 2}]
Note the rescaled pie chart. I am sure I could pimp my function a lot more to handle this automatically, all suggestions are welcome. But my main question would be: Is there an easier way that uses the built-in SectorChart
, PieChart
, etc. commands together with a radial color function? (of course I still need the colorbar
.)