フィルターのクリア

Latex formatting on heatmaps (labels, title and all other text)

56 ビュー (過去 30 日間)
Steeven
Steeven 2018 年 3 月 22 日
編集済み: Benjamin Kraus 2023 年 9 月 20 日

When creating a heatmap and a contour plot from the same table data with the code:

xvalues = {'20 $^\circ$C','30 $^\circ$C','40 $^\circ$C','50 $^\circ$C','60 $^\circ$C','70 $^\circ$C','80 $^\circ$C','90 $^\circ$C'};
yvalues = {'98 \%','90 \%','80 \%','70 \%','60 \%','50 \%','40 \%'};
c=heatmap(xvalues,yvalues,table)
contourf(table)
set(gca,'xticklabel',xvalues)
set(gca,'yticklabel',yvalues)

it turns out that my globally set latex formatting only affects the contour plot:

The heatmap keeps a default font while the contour plot shows the recognizable latex font. And all $...$ latex syntax is written out in clear text on the heatmap but correctly interpreted by the contour plot.

The MatLab code lines I use for applying latex formatting are put in the top of the live-script MatLab file that I am working in:

set(groot,'defaulttextinterpreter','latex');  
set(groot, 'defaultAxesTickLabelInterpreter','latex');  
set(groot, 'defaultLegendInterpreter','latex'); 

I am aware that those code lines might not target the "object", which the heatmap is. Any advice on how to apply the latex syntax on all text (labels, titles etc.) in all types of objects?

  5 件のコメント
Steeven
Steeven 2018 年 3 月 22 日
@VonDuesenberg. Why would you expect this to have any effect? The Latex clearly works for one graph but not the other; should doubling the sign change the interpretation?
In any case, thanks for the suggestion. It has now been tried, and it didn't work, unfortunately. The doubled dollar signs are just written out in clear text.
Von Duesenberg
Von Duesenberg 2018 年 3 月 22 日
Well sorry to hear that. I had an unexpected behaviour with Latex in axes a couple of weeks ago and the double dollar solved my problem, so I made the suggestion just in case.

サインインしてコメントする。

回答 (2 件)

Benjamin Kraus
Benjamin Kraus 2023 年 9 月 20 日
編集済み: Benjamin Kraus 2023 年 9 月 20 日
Starting in MATLAB R2023b, the HeatmapChart now has an Interpreter property.
xvalues = {'20 $^\circ$C','30 $^\circ$C','40 $^\circ$C','50 $^\circ$C','60 $^\circ$C','70 $^\circ$C','80 $^\circ$C','90 $^\circ$C'};
yvalues = {'98 \%','90 \%','80 \%','70 \%','60 \%','50 \%','40 \%'};
h = heatmap(xvalues,yvalues,rand(7,8));
h.Interpreter = 'latex';

Kamran Pentlan
Kamran Pentlan 2021 年 8 月 27 日
編集済み: Kamran Pentlan 2021 年 8 月 27 日
This should work for including LaTeX on the axes and title. It did for me!
figure(1)
h = heatmap(rand(3,3));
h.XLabel = '$u_1$';
h.YLabel = '$u_2$';
h.Title = '$x^y$';
h.NodeChildren(3).XAxis.Label.Interpreter = 'latex';
h.NodeChildren(3).YAxis.Label.Interpreter = 'latex';
h.NodeChildren(3).Title.Interpreter = 'latex';

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by