I have a PieChart that needs a formatted label. Since some of the sectors are small I want to use Callout for those but keep the label for the others.

This concept works for basic data.

assoc = <|"a" -> 1., "b" -> 2., "c" -> 5., "d" -> 3.|>;
PieChart[If[# < 2, Callout, Labeled][#, NumberForm[#, {2, 1}]] & /@ assoc]

Mathematica graphics

However, when evaluated on some other Associations the PieChart gives a FindMinimum error and does not produce the expected result. None of the Callouts appear.

assoc2 = <|"a" -> 20.1230, "b" -> 0, "c" -> 0, "d" -> 0, 
   "e" -> 18.6519, "f" -> 32.9057, "g" -> 18.2365, "h" -> 1.2884, 
   "i" -> 5.9057, "j" -> 2.8403, "k" -> 0, "l" -> 0, "m" -> 0, 
   "n" -> 1.8480, "o" -> 0|>;
PieChart[If[# < 2, Callout, Labeled][#, NumberForm[#, {2, 1}]] & /@ assoc2]

FindMinimum::eqineq: Constraints in {False} are not all equality or inequality constraints. With the exception of integer domain constraints for linear programming, domain constraints or constraints with Unequal (!=) are not supported.

Mathematica graphics

Is this a bug? Any ideas how to work around this? version 11.1.0 on Win 7 Ent

CASE: 3883154


The difficulty is that you have multiple zeroes right next to each other in the data set. This is causing difficulty with the positioning algorithm which uses FindMinimum. To some extent, this is pathological data, but Callout should not completely collapse under this condition:

enter image description here

The workaround would be to separate the zero data, or to coalesce them together.

| improve this answer | |
  • $\begingroup$ I don't think I want to remove them as there are many of these datasets that are returned from the process and there is a list of colours that must be the same across all of the plots. However with your info I can swap out the If statement for Which[# > 2, Labeled, # > 0, Callout, True, #1 &] which avoids wrapping the zeros. +1 for now. $\endgroup$ – Edmund Apr 26 '17 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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