5

I am looking for a way to manually control the positioning of labels in a 3D plot. For this purpose I used to follow the methods of the accepted answers in:

Axes Origin & Labels in 3D Plot

Manually assigning Axes label position in Plot3D

which basically achieves that using Show and something like

Graphics3D[Text["x", Scaled[{0.5, -0.2, -0.2}] ]

I'm guessing this has something to do with the version 13.1, but this no longer works. In this version I can't even reproduce the accepted solutions above anymore. The labels simply don't show up.

Example:

Show[{Plot3D[x^2 + y^2 + 3, {x, -3, 3}, {y, -3, 3},PlotRange -> {-1, 20}],Graphics3D[{Text["x", Scaled[{-.05, .5, 0}], {0, -1}], Text["y", Scaled[{.5, -.05, 0}], {0, -1}], Text["z", Scaled[{.5, .5, 1.1}]]}]}]

returns:

enter image description here

no x y z labels...

I think the problem is that Scaled brings the label outside the boundingbox of Graphics3D, but PlotRange doesn't fix that. I can play with Scaled to bring the labels into the plot. In this picture it still may look fine to bring the labels inside, but in other cases it doesn't.

Also, if possibe, I'd like the answer not to involve the function Text, because for aesthetic reasons I use the package Matex, to produce labels as in

Graphics3D[Inset[MaTeX["x"], Scaled[{0.5, -0.2, -0.2}] ] ]

and hence some functionalities of Text may not carry over. Alternatives to this approach are also welcome though. Thank you.

RL's
  • 53
  • 5

2 Answers2

3
  • For Graphics3D,Inset work.
ResourceFunction["MaTeXInstall"][];
<< MaTeX`
Graphics3D[{{Opacity[.2], Cuboid[]}, 
  Inset[MaTeX["x", Magnification -> 4], {0.5, -0.2, -0.2}], 
  Inset[MaTeX["O", Magnification -> 4], {0.5, 0.5, 0.5}]}, 
 Boxed -> False]

enter image description here

  • Plot3D, we can also use AxesLabel and Labeled.
<< MaTeX`

Plot3D[Labeled[x^2 + y^2 + 3, MaTeX["\mathcal{A}", Magnification -> 2], {.5, .5}, Background -> None], {x, -3, 3}, {y, -3, 3}, PlotRange -> {-1, 20}, AxesLabel -> {MaTeX["x", Magnification -> 3], MaTeX["y", Magnification -> 3], MaTeX["z", Magnification -> 3]}]

enter image description here

cvgmt
  • 72,231
  • 4
  • 75
  • 133
  • What font isMaTeX using? Very pretty! – Nicholas G Aug 24 '22 at 00:13
  • 1
    @NicholasG Here is the default font of LaTeX ,we can set another fonts as show in http://szhorvat.net/pelican/latex-typesetting-in-mathematica.html – cvgmt Aug 24 '22 at 00:15
  • Many thanks. I do not see the font Latin Modern in my PC installation of 13.1. There is a Modern No. 20, which seems somewhat close. – Nicholas G Aug 24 '22 at 00:21
  • Graphics3D[{{Opacity[.2], Cuboid[]}, Inset[MaTeX["x", Magnification -> 4], {0.5, -.2, 0}, Automatic, Automatic, AngleVector[-π/10]], Inset[MaTeX["y", Magnification -> 4], {1.2, .5, 0}, Automatic, Automatic, AngleVector[-π/6]], Inset[MaTeX["z", Magnification -> 4], {1.2, 1, .5}], Inset[MaTeX["O", Magnification -> 4], {0.5, 0.5, 0.5}]}, Boxed -> False] – cvgmt Aug 24 '22 at 14:30
  • I am not sure I understand your answer. If LaTeX uses the font Latin Modern, as it seems to do, then the font Latin Modern must be a publicly available font, and I should be able to install it and use it directly from Mathematica without having to install MaTeX. No? – Nicholas G Aug 25 '22 at 11:23
  • @NicholasG I have install TeXLive 2022, there lots of fonts in this TeX system. – cvgmt Aug 25 '22 at 11:57
  • @NicholasG In my computer,I have install TeXLive 2022, and MaTeX use the available fonts in TeXLive 2022 and in the Win system. – cvgmt Aug 25 '22 at 11:58
2

Here is a more precise way to do that where you can arbitrary control the positions of labels and even rotate

lebl = MaTeX["\\color{red}\\text{Lable}", FontSize -> 14];
axeslebl = MaTeX[#, FontSize -> 14] & /@ {"X", "Y", "Z"};   

then you get (Note that LM Roman 12 is the same font as MaTeX)

Plot3D[x^2 + y^2 + 3, {x, -3, 3}, {y, -3, 3}, PlotRange -> {-1, 20}, 
 LabelStyle -> {FontFamily -> "LM Roman 12", Black, FontSize -> 14}, 
 Epilog -> {Text[lebl, Scaled[{.5, 1.1}]], 
   Rotate[Text[axeslebl[[1]], Scaled[{.25, 0.02}]], -\[Pi]/10], 
   Rotate[Text[axeslebl[[2]], Scaled[{.94, 0.2}]], \[Pi]/3], 
   Rotate[Text[axeslebl[[3]], Scaled[{-0.1, 0.5}]], \[Pi]/1.8]}, 
 ImagePadding -> 40, AspectRatio -> 1]     

enter image description here

MMA13
  • 4,664
  • 3
  • 15
  • 21