2
$\begingroup$

Observe the inconsistency in the appearance of the title on the following plots:

label = "\!\(\*SqrtBox[\(Test\)]\)"

Plot[{t, t^2}, {t, 0, 1}, PlotLabel -> label]

Plot[{t, t^2}, {t, 0, 1}, PlotLabel -> label, 
  PlotLegends -> ""]

Plot[{t, t^2}, {t, 0, 1}, PlotLabel -> label, 
  PlotLegends -> Placed[Automatic, 
    {Right, Center}]]

The output of "label" and the title of the second Plot entry appear as

enter image description here

but the titles of the first and third Plot entries appear as

enter image description here

What's going on here, and how can I consistently produce the first (smaller) appearance in plot titles regardless of the PlotLegend setting? The trick of using the dummy setting PlotLegends->"" will not work because I am trying to place a legend inside my plot image, as in the third entry.


Incidentally, this issue only seems to arise when capital letters are used inside the square root sign. If "Test" is replaced with "test", for example, the issue vanishes. But alas, I need to place a combination of lowercase and uppercase letters under the square root sign in my application.


EDIT:

There was an answer (now deleted, for some reason) suggesting

Plot[{t, t^2}, {t, 0, 1}, PlotLegends -> 
     {Placed[label, 
         {Top, Center}], Placed[Automatic, 
         {Right, Center}]}]

This works except that now "Test" is formatted with a different style from typical PlotLabel. It is formatted with the same style as the output of label, which is different from that of PlotLabel, as pointed out by Michael E2 in the comments.

To see the difference observe the output of

Plot[{t, t^2}, {t, 0, 1}, PlotLabel -> label, 
   PlotLegends -> 
     {Placed[label, 
         {Top, Center}], ""}]

enter image description here


Incidentally, I have found another solution that seems to work:

Labeled[Plot[{t, t^2}, {t, 0, 1}, 
     PlotLabel -> label], ""]

Still, seems hacky and it would be nice to understand what's going on with the different display styles.


EDIT 2:

The workaround I proposed just above actually isn't ideal because when I save as PDF, the blank label creates extra space under the plot image. Also, as an added wrinkle, even when using this trick, right-clicking the image and then choosing "Save Graphic As..." and saving as a PDF reverts the label to the "bad" form with too much space inside the square root sign! After selecting the whole cell, right-clicking and choosing "Save Selection As..." and saving as a PDF, the square root prints properly but the blank space is added at the bottom. What a mess!

$\endgroup$
5
  • $\begingroup$ I'm curious if there's a WL equivalent for $\TeX$'s \vphantom. As a way to perhaps force all roots to conform to the tallest character. $\endgroup$
    – Adam
    Mar 17 at 0:24
  • $\begingroup$ The output of label is typeset with a different style than in Plot. My plots all have the same look (V12.2, Mac). -- The output of Style[label, "Graphics", Larger] seems to match my plots. $\endgroup$
    – Michael E2
    Mar 17 at 0:30
  • $\begingroup$ I have V12.0 Mac, so maybe the upgrade fixes the issue, though I'm not sure I have access to V12.2. $\endgroup$
    – WillG
    Mar 17 at 14:33
  • 1
    $\begingroup$ My plots also all have the same look (v12.2 on Windows 10), so probably this was fixed. Also, I suggest using the MaTeX package for nicer-looking and perfectly uniform labels... $\endgroup$ Mar 22 at 15:14
  • $\begingroup$ @FidelI.Schaposnik I just updated to 12.2 and that fixed the problem. So I guess the best solution was the simplest after all. $\endgroup$
    – WillG
    Mar 22 at 16:25
2
+50
$\begingroup$

Based upon my tests and the comments to the original question, it appears that this problem does not occur in Mathematica 12.2. The recommended solution is therefore to upgrade.

$\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.