3
$\begingroup$

I am trying to plot a ListPlot where each point has a label. Unfortunately Mathematica seems to decide that is a label is too large, it will not show it. I would very much like all the labels to be shown! Any help would be much appreciated.

MWE:

ListPlot[{1, 1, 0.75, 0.75, 0.6, 0.6, 0.6, 0.6, 0.2, 0.2, 0.2, 0.2} ->
    {a1, a2, 2 b1 + b2, b2, c1, c2 + c3 - c1, c3 - c2 + c1, c4,d1, d2, d3, d4}]

Not all points are shown

Notice that the points that should be labeled c2 + c3 - c1 and c3 - c2 + c1 are missing their label. I know that if I set ImageSize->Large these will show, but I want to use this within a manipulate environment whereby the number of points will change and don't want to set a huge plot when it may only contain a small number of points, and if the number of points gets larger then ImageSize->Full may not be good enough.

$\endgroup$
  • $\begingroup$ While acknowledging that this does not answer your question; note that for those points for which the label is suppressed, the label is converted to a Tooltip which can be seen when the mouse is over the point. $\endgroup$ – Bob Hanlon Oct 22 '18 at 2:46
3
$\begingroup$

I am uncertain how large your labels may grow. To me it seems impossible to print many large labels on a small figure. I can only offer answers obtained by trial and error and by "jittering" points:

  • just putting the labels between quotation marks shows the labels literally and helps somewhat (figure 1);
  • "jittering" (adding a negligible amount of 'noise' to the values) helps a lot (figure 2).

I wonder wether this solution works within your manipulate environment. May be it is also possible to use a smaller font.

ListPlot[{1, 1, 0.75, 0.75, 0.6, 0.6, 0.6, 0.6, 0.2, 0.2, 0.2, 
   0.2} -> {"a1", "a2", "2 b1+b2", "b2", "c1", "c2+c3-c1", "c3-c2+c1",
    "c4", "d1", "d2", "d3", "d4"}]

enter image description here

Now I add 0.000001 to the 11th value and make its label even longer.

ListPlot[{1, 1, 0.75, 0.75, 0.6, 0.6, 0.6, 0.6, 0.2, 0.2, 0.200001, 
   0.2} -> {"a1", "a2", "2 b1+b2", "b2", "c1", "c2+c3-c1", "c3-c2+c1",
    "c4", "d1", "d2", "d3+q1+w3+z6+h7", "d4"}]

enter image description here

$\endgroup$
  • $\begingroup$ Does mapping TraditionalForm or StandardForm on the labels work? $\endgroup$ – J. M. is away Oct 20 '18 at 18:52
1
$\begingroup$

If the number of points is not "too large": Plot with the option ImageSize -> Full and use the result in Show with desired ImageSize:

Show[ListPlot[{1, 1, 0.75, 0.75, 0.6, 0.6, 0.6, 0.6, 0.2, 0.2, 0.2,  0.2} ->
       {a1, a2, 2 b1 + b2, b2, c1, c2 + c3 - c1, c3 - c2 + c1, c4,  d1, d2, d3, d4}, 
   ImageSize -> Full], 
  ImageSize -> Medium]

enter image description here

Some labels are still suppressed if the number points is too large:

data = RandomInteger[100, {200, 2}];
labels = RandomWord["Noun", 200];
Show[ListPlot[data -> labels, ImageSize -> Full], ImageSize -> Large]

enter image description here

$\endgroup$

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.