1
$\begingroup$

is there a way to put the labels on this pie chart (e.g. {"c1", "c2", "c3"}) at a distance from the origin on the slices between "RadialCenter" and "RadialOuter"? E.g. is there a way to tune the precise location of the location of ChartLabels by specifying some distance from the origin? I considered attempting to use Placed , but for pie charts in Mathematical it looks like there are only three options.

PieChart[{{1, 2, 3}}, 
 ChartLabels -> {Placed[{"c1", "c2", "c3"}, "RadialOuter"]}, 
 SectorSpacing -> 0.5]

thanks!

$\endgroup$

1 Answer 1

1
$\begingroup$

You can post-process the output of PieChart to change the positions of Text objects:

{ro, rc} = PieChart[{{1, 2, 3}}, 
      ChartLabels -> {Placed[{"c1", "c2", "c3"}, #]}, 
      SectorSpacing -> 0.5, ImageSize -> 300, PlotLabel -> #] & /@ 
   {"RadialOuter", "RadialCenter"};

Row[{ro, rc}]

enter image description here

{radiuso, radiusc} = First@Cases[#, Text[_, p_, ___] :> Norm[p], All] & /@ {ro, rc}
 {0.9, 0.666667}
rm = Show[rc /. Text[t_, p_, x___] :> 
    Text[t, Mean[{radiuso, radiusc}] Normalize[p], x], 
  PlotLabel -> "mean(RadialCenter,RadialOuter)"]

enter image description here

epilog = {Blue, Circle[{0, 0}, Mean[{radiuso, radiusc}]], Red, 
   Circle[{0, 0}, radiuso], Green, Circle[{0, 0}, radiusc]};

Row[Show[#, Epilog -> epilog] & /@ {ro, rc, rm}]

enter image description here

Using Manipulate to interactively control the radial positions of labels:

symbolicpositions = {"RadialInner", "RadialInside", "RadialCenter", 
   "RadialOuter", "RadialEdge", "RadialOutside"};

radii = First @ Cases[PieChart[{1}, ChartLabels -> Placed[{"c1"}, #]], 
      Text[_, p_, ___] :> Norm[p], All] & /@ symbolicpositions;

Manipulate[Legended[Show[
   rc /. Text[t_, p_, x___] :> Text[t, radius Normalize[p], x], 
   ImageSize -> 500, PlotLabel -> None, 
   PlotRange -> {3/{-2, 2}, 3/{-2, 2}}, 
   Epilog -> {Green, Circle[{0, 0}, radiusc], Blue, 
     Circle[{0, 0}, radiuso], Thick, Red, Circle[{0, 0}, radius]}], 
  LineLegend[{Green, Blue}, {"RadialCenter", "RadialOutside"}]], 
 Row[{"radius", 
   Column[{Control @ {{radius, Mean[{radiuso, radiusc}], ""}, 
       Thread[radii -> symbolicpositions], ControlType -> SetterBar}, 
     Control @ {{radius, Mean[{radiuso, radiusc}], ""}, 0, 2, 
       Appearance -> "Labeled", ImageSize -> Large}}]}], 
 Alignment -> Center]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.