How can I italicize the label of a heatmap?

24 ビュー (過去 30 日間)
Baolei Wu
Baolei Wu 2018 年 11 月 29 日
編集済み: Benjamin Kraus 2023 年 9 月 20 日
I just can not italicize the colume labels using the "\it" command. How can I fix it?
figure
xvalues=linspace(1,8,8);
yvalues={"\it Campylobacter (gull,+)","{\it Salmonella} (gull,+)", "nororvirus (sewage,+)", "adenovirus (sewage,-)", ...
"{\it Campylobacter} (sewage,+)","{\it Salmonella} (sewage,+)","{\it E.coli} O157:H7 (sewage,+)","{\it Cryptosporidium} (sewage,+)",...
"{\it Giardia} (sewage,+)", "norovirus (effluent,+)", "adenovirus (effluent,-)","{\it Cryptosporidium} (effluent,+)",...
"{\it Giardia} (effluent,+)","{\it Campylobacter} (cattle,+)","{\it Salmonella} (cattle,+)","{\it E. coli} O157:H7 (cattle,+)",...
"{\it Cryptosporidium} (cattle,+)","{\it Giardia} (cattle,+)"};
htmap=heatmap(xvalues,yvalues,mprtable);
htmap.Colormap=redblue;
set(gca,'XLabel','GeM concentration (GC/100 mL)','YLabel','R_p');
itbug.jpg

採用された回答

Benjamin Kraus
Benjamin Kraus 2023 年 9 月 20 日
編集済み: Benjamin Kraus 2023 年 9 月 20 日
Heatmap does allow you to customize the X and Y tick labels, by setting the XData and YData properties (alternatively, you can set the XDisplayLabels or YDisplayLabels properties).
Since R2019a the default interpreter for heatmap is set to 'tex' so you can use special characters (such as \it) to create italic text. Prior to R2019a, if you wanted to use 'tex' or 'latex' interpretted characters, you can use the answer by @Adam Danz (click here).
Starting in R2023b, you can also change the interpreter used by setting the new Interpreter property.
xvalues=linspace(1,8,8);
yvalues={"\it Campylobacter (gull,+)","{\it Salmonella} (gull,+)", "nororvirus (sewage,+)", "adenovirus (sewage,-)", ...
"{\it Campylobacter} (sewage,+)","{\it Salmonella} (sewage,+)","{\it E.coli} O157:H7 (sewage,+)","{\it Cryptosporidium} (sewage,+)",...
"{\it Giardia} (sewage,+)", "norovirus (effluent,+)", "adenovirus (effluent,-)","{\it Cryptosporidium} (effluent,+)",...
"{\it Giardia} (effluent,+)","{\it Campylobacter} (cattle,+)","{\it Salmonella} (cattle,+)","{\it E. coli} O157:H7 (cattle,+)",...
"{\it Cryptosporidium} (cattle,+)","{\it Giardia} (cattle,+)"};
htmap=heatmap(xvalues,yvalues,rand(18,8));
htmap.XLabel = 'GeM concentration (GC/100 mL)';
htmap.YLabel = 'R_p';
htmap.XData = xvalues;
htmap.YData = yvalues;

その他の回答 (1 件)

Adam Danz
Adam Danz 2018 年 11 月 29 日
編集済み: Adam Danz 2020 年 1 月 3 日
The heatmap() function (released 2017a) unfortunately doesn't provide handles to the column and row labels so there's no way of changing their 'interpreter' so that the italics is recognized. I don't think it's even possible to get access to those handles using methods such as findall() (I tried).
The older HeatMap() function (released 2009b, Bioinformatics toolbox) is more customizable. For example, the addYLabel() function allows users to customize the row labels but it only works with the older version of HeatMap().
If you really need to make that change, one hacky method would be to remove the row labels, put a 2nd transparent axes over top of the heatmap, calculate where each row-center is, and then set the yticks and ylabels.
h = heatmap(xvalues,yvalues,cdata);
h.YDisplayLabels = repmat({''}, size(h.YData)); %remove row labels
a2 = axes('Position', h.Position); %new axis on top
a2.Color = 'none'; %new axis transparent
a2.YTick = 1:size(h.ColorData,1); %set y ticks to number of rows
a2.XTick = []; %Remove xtick
% alternatively, to preserve axis label spacing :
% a2.XTickLabel = repmat({' '}, size(a2.XTick));
ylim(a2, [0.5, size(h.ColorData,1)+.5]) %center the tick marks
a2.YDir = 'Reverse'; %flip your y axis to correspond with heatmap's
a2.YTickLabel = {'\it Green','\it Red',...}; %set you ytick labels here, formatted.
Applying this to matlab's heatmap example produces the following plot.
  7 件のコメント
DanielFromIllinois
DanielFromIllinois 2021 年 1 月 7 日
This makes me sad inside.
Adam Danz
Adam Danz 2021 年 1 月 7 日
@Daniel, see this link to turn that frown upside down.

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

カテゴリ

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

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by