LaTex interpreter in Heatmap ax-label

I want to use the LaTex interpreter in the xlabel and ylabel of a Heatmap plot.
I know how to do it for the plot() command, where I just have to write (it is just an example, and it works):
plot(x, f(x))
xlabel('$x$','Interpreter','latex')
ylabel('$f(x)$','Interpreter','latex')
The command heatmap() doesn't seem to work like the plot() command. Here's the code I'm using, where the variable Err is a MxM matrix:
heatmap(M,M,Err)
xlabel('$M_{1}$','Interpreter','latex')
ylabel('$M_{2}$','Interpreter','latex')
from which I receive the following error code:
Error using matlab.graphics.chart.Chart/xlabel
Too many input arguments specified when using xlabel with heatmap.
If I don't write the string 'Interpreter','latex' leaving just
heatmap(M,M,Err)
xlabel('$M_{1}$')
ylabel('$M_{2}$')
the code works but the label looks like in the figure:

3 Comments

did you try something like
set(findall(gcf,'-property','Interpreter'),'Interpreter','latex')
?
I just tried, but nothing changes. I see the same things of the question.
If I recall correctly, you cannot set the Interpreter for heatmap objects.

Sign in to comment.

 Accepted Answer

Starting in MATLAB R2023b, the HeatmapChart now has an Interpreter property.
h = heatmap(rand(30));
h.XLabel = '$M_{1}$';
h.YLabel = '$M_{2}$';
h.Interpreter = 'latex';

More Answers (1)

h = heatmap(M,M,Err);
h.XLabel = 'M{_1}';
h.YLabel = 'M{_2}';

11 Comments

That looks like TeX interpreter, not LaTex.
Yes, I'm using the (default) TeX interpreter. I assuming Andrea's real goal is just to get the appropriate labels in the axes.
"I want to use the LaTex interpreter in the xlabel and ylabel of a Heatmap plot."
Seems pretty specific.
Ok, maybe I explained myself wrong, in case I apologize to you.
My goal is to get the appropriate labels in the axes, that is, the math environment style ($...$) of latex.
I am able to subscript M (as you can see from the figure of the question), and also to write tha labels in italics (with a simpre \it before M_1 and M_2). In this way, the labels look like what I want to achieve, but they are not the same.
Is there any other way?
OK, I'm still not sure what you want. I assume it's one of the following:
Can you clarify please?
What I want is simply what I would get on latex with the command $M_{1}$, with the default latex font.
The problem is that the default latex font is "Computer Modern", that is not in the listfonts of matlab.
The only way to get it is to use: 'Interpreter', 'latex'. But with the heatmap it is not possible.
Hmm, your question didn't mention anything about fonts. Sorry if I misunderstood.
My fault, I didn't explicitly mention the fonts just because with any other command (e.g., plot()) 'Interpreter', 'latex' solve my problem.
Also the spacing and bold rendering are different for latex compared to tex
Any suggestions to overcome these issues? Thanks for the answers, btw.
No really. It seems, as noted in a comment from Walter, that you can't set the Interpreter for heatmap objects.
You might consider re-stating your objective, perhaps in another question, without reference to latex.

Sign in to comment.

Categories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!