Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

PieChart has the nice functionality of highlighting a single pie when you click on it. It is then sticking out a little. See the following example:

PieChart[{1, 2, 3}]

enter image description here

Now, if I click on the green Pie it starts to stick out.

enter image description here

Is there any way of achieving this programmatically? I browsed through the Options of PieChart but couldn't find anything. I want to automatically create a number of plots with highlighted sections and save them automatically without having to click on them manually each time.

share|improve this question
There is DynamicModule created which scoped variables are only those responsibile for this. Initial values are set to False, each click changes it to True etc. If you can reconstruct those boxes so that initial value of desired variable is True then it will start as highlighted. – Kuba Feb 12 '14 at 21:24
up vote 20 down vote accepted

Something like this perhaps. Thanks to halmir for pointing out that multiple highlighted elements might be useful.

pieHighlight[chart_, n_] := chart /. DynamicModule[init_, body__] :> 
 (ReplacePart[Hold[init], Thread @ {1, n, 2} -> True] /. 
     Hold[x_] :> DynamicModule[x, body])


PieChart[{1, 2, 3}] ~pieHighlight~ 2

enter image description here

PieChart[{1, 2, 3}] ~pieHighlight~ {1, 2} 

enter image description here

share|improve this answer
nice! you could change {1, n, 2} -> True to {1, #, 2} & /@ Flatten[{n}] -> True to allow multiple open pie. i.e, PieChart[{1, 2, 3}]~pieHighlight~{1, 3} – halmir Feb 12 '14 at 22:38
@halmir, good idea to allow multiple highlighted sections, but I prefer Thread@{1, n, 2} – Simon Woods Feb 13 '14 at 10:16

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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