5
$\begingroup$

Bug persists through 12.0.


I'm trying to produce a plot with PlotLabels that include sub- and superscripts. However, I haven't been able to do it consistently. Currently I'm trying to do this with the basic math assistant palette and the code is thus:

Plot[30, {x, 0, 605}, PlotStyle -> {Dashed, Thick, Black}, 
PlotLabels -> "\!\(\*SubsuperscriptBox[\(x\), \(s\), \(*\)]\)"]

But there is rather strange gap between the plot and the label which you can see from the picture below. Is there a way to move the label closer to the plot?

enter image description here

Running the same code without the sub and superscripts produces no issue.

$\endgroup$
3
$\begingroup$

Looks like a bug in PlotLabels to me - my guess is that when measuring the size of the label, it does not take into account how big the rendered string will be, only the raw (rather long) string. A work-around is to wrap the label in Row@{...}:

Plot[30, {x, 0, 605},
 PlotStyle -> {Dashed, Thick, Black}, 
 PlotLabels -> Row@{
  "\!\(\*SubsuperscriptBox[\(x\), \(s\), \(*\)]\)"
 }
]

enter image description here

Other potential wrappers include StandardForm[...] and TraditionalForm[...] (which will render the label a bit differently) - essentially anything that hides the raw string from PlotLabels seems to do the trick.

| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Ah that explains why removing either the sub or the superscript only made the gap slightly shorter. I tried couple of workarounds with InputForm etc. without a positive results. However, Row seems to do it. Thank you. $\endgroup$ – Harto Saarinen Oct 15 '19 at 11:21
  • 1
    $\begingroup$ @HartoSaarinen Please consider writing a bug report on the issue to support(at)wolfram.com. $\endgroup$ – Alexey Popkov Oct 15 '19 at 11:59
  • 1
    $\begingroup$ Pane also works as well for a workaround $\endgroup$ – chuy Oct 15 '19 at 16:02

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.