How can I italicize the label of a heatmap?

조회 수: 23 (최근 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 CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by