How can I italicize the label of a heatmap?
15 次查看(过去 30 天)
显示 更早的评论
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');
0 个评论
采纳的回答
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;
0 个评论
更多回答(1 个)
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.
7 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!