5
$\begingroup$

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.

$\endgroup$

2 Answers 2

2
$\begingroup$

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

$\endgroup$
3
$\begingroup$
  • 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

$\endgroup$
7
  • $\begingroup$ What font isMaTeX using? Very pretty! $\endgroup$
    – Nicholas G
    Aug 24, 2022 at 0:13
  • 1
    $\begingroup$ @NicholasG Here is the default font of LaTeX ,we can set another fonts as show in szhorvat.net/pelican/latex-typesetting-in-mathematica.html $\endgroup$
    – cvgmt
    Aug 24, 2022 at 0:15
  • $\begingroup$ 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. $\endgroup$
    – Nicholas G
    Aug 24, 2022 at 0:21
  • $\begingroup$ 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] $\endgroup$
    – cvgmt
    Aug 24, 2022 at 14:30
  • $\begingroup$ 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? $\endgroup$
    – Nicholas G
    Aug 25, 2022 at 11:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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