MATLAB Answers

How do I change axes font (heatmap)?

12 views (last 30 days)
M.G.
M.G. on 28 May 2020
Commented: M.G. on 29 May 2020
Hello everyone,
I need to get a heatmap with all fonts being Times New Roman. I had no problems with heatmap values, more troubles with x axis font and I still can't change y axis font.
I am using this code:
h=heatmap(X, Y, C, 'FontName', 'Times New Roman');
h.xlabel('Something (unit)');
h.xlabel('FontName', 'Times New Roman');
h.ylabel('Something else (unit)');
h.ylabel('FontName', 'Times New Roman');
colormap(mymap)
And what I get is a heatmap with no y axis label. Everything else is alright. What am I missing here?

  0 Comments

Sign in to comment.

Accepted Answer

Tommy
Tommy on 29 May 2020
Your code is crashing at this line:
h.xlabel('FontName', 'Times New Roman');
The x label is set properly because of the previous line, and the y label is never set because the following line is never reached.
The x label has Times New Roman font because you specified that the heatmap's font should be Times New Roman when you called heatmap(). So this should work:
h=heatmap(X, Y, C, 'FontName', 'Times New Roman');
h.xlabel('Something (unit)');
h.ylabel('Something else (unit)');
colormap(mymap)

  3 Comments

M.G.
M.G. on 29 May 2020
It worked, thank you.
But what do I do if I want to have axes label written in bold?
It doesn't work neither with:
h=heatmap(X, Y, C, 'FontName', 'Times New Roman', 'FontWeight', 'bold');
h.xlabel('something');
h.ylabel('something else');
colormap(mymap)
nor with:
h=heatmap(X, Y, C, 'FontName', 'Times New Roman');
h.xlabel('something', 'FontWeight', 'bold');
h.ylabel('something else', 'FontWeight', 'bold');
colormap(mymap)
Tommy
Tommy on 29 May 2020
Happy to help!
Heatmaps use the TeX text interpreter by default. To specify bolded text, put '\bf' before the text you would like to bold.
h=heatmap(X, Y, C, 'FontName', 'Times New Roman');
h.xlabel('\bf something');
h.ylabel('something \bf else');
colormap(mymap)
See here for general info about TeX.
See here for a complete list of properties you can set for a Heatmap.
M.G.
M.G. on 29 May 2020
That worked! Thank you very much :)

Sign in to comment.

More Answers (0)

Products


Release

R2020a

Translated by