3
$\begingroup$

I am trying to create a 3D density plot and use LaTeX to render the axis labels. My code is below. When I comment out the AxesLabel command the code runs fine and, in particular, MaTeX renders the legend label correctly. What am I doing wrong?

<< MaTeX`
texStyle = {FontFamily -> "Latin Modern Roman", FontSize -> 15, Black};

f[x_, y_, z_] := Cos[x] Cos[y] Cos[z]

DensityPlot3D[
 f[x, y, z],
 {x, 0, 2 \[Pi]},
 {y, 0, 2 \[Pi]},
 {z, 0, 2 \[Pi]},
 AxesLabel\[Rule]{MaTeX["x"],MaTeX["y"],MaTeX["z"]},
 
 LabelStyle -> texStyle,
 PlotLegends -> BarLegend[
   Automatic,
   LegendMarkerSize -> 300,
   LegendLabel -> MaTeX["f(\\vec{x})", Magnification -> 2]]
 ]

When I try to run it, I get these errors:

ReplacePart::reps: {1->x,2->y,5,2->y,2->y,2->y,5,2->y,3->z,2->y,<<2>>} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.

ReplacePart::reps: {1->6.28318,2->6.28318,5,2->6.28318,2->6.28318,2->6.28318,5,2->6.28318,3->6.28318,2->6.28318,<<2>>} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.

$\endgroup$
1
  • 1
    $\begingroup$ this looks like an issue with DensityPlot3D itself and not MaTeX. ClearAll[f, x, y, z]; f[x_, y_, z_] := Cos[x] Cos[y] Cos[z]; labels = {MaTeX["x"], MaTeX["y"], MaTeX["z"]}; and now DensityPlot3D[ f[x, y, z], {x, 0, 2 \[Pi]}, {y, 0, 2 \[Pi]}, {z, 0, 2 \[Pi]}, AxesLabel -> labels] gives error, but ContourPlot3D[ f[x, y, z], {x, 0, 2 \[Pi]}, {y, 0, 2 \[Pi]}, {z, 0, 2 \[Pi]}, AxesLabel -> labels] works. $\endgroup$
    – Nasser
    Commented Oct 7, 2021 at 1:17

1 Answer 1

1
$\begingroup$

For me, I have 12.0.0 and a brand new MaTex installation with MacTex, the extra $MaTex$ function is obsolete. I already get the assumed result with:

DensityPlot3D[
 f[x, y, z], {x, 0, 2 \[Pi]}, {y, 0, 2 \[Pi]}, {z, 0, 2 \[Pi]}, 
 AxesLabel -> {x, y, z}, LabelStyle -> texStyle]

DensityPlot3D

I after that simplification the following output density plot:

DensityPlot3D[
 f[x, y, z], {x, 0, 2 \[Pi]}, {y, 0, 2 \[Pi]}, {z, 0, 2 \[Pi]}, 
 AxesLabel -> {x, y, z}, LabelStyle -> texStyle, 
 PlotLegends -> 
  BarLegend[Automatic, LegendMarkerSize -> 300, 
   LegendLabel -> MaTeX["f(\\vec{x})", Magnification -> 2]]]

density plot with bar legend

But there remains questions whether the shadow to the left of the color gradient legend bar is intended or flaw?

The problem You have is to understand that the option $LabelStyle$ is enough for the option $AxesLabel$ to be formatted in LaTex already. Or on the other hand the $MaTex$ has to be given the option from the $LabelStyle$ is an manner accustomed to it. Look at both documentation and separate in the future both paths of formatting nice and large labels for example.

MaTex uses the options BasePreamble, FontSize, Magnification, ... directly in the built-in or as an external definition if more complex but this has to be used in the MaTex as content for an option. The MaTex symbol

Mathematica has LaTex font onboard and looks nice and impressive too with this. Otherwise there is a usage on the documentation page with the # functions form slots.

So excuse that my fonts are different by my only making clear where the misconception is present and leave the comfortable and in-depth alternative to the proper solution to the documentation.

$BaseStyle$ is another workaround for the problem and so on. So in my solution quick and dirty for this answer just the string $f(x)$ is LaTex.

$\endgroup$

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.