How can I italicize the label of a heatmap?

23 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Benjamin Kraus
Benjamin Kraus il 20 Set 2023
Modificato: Benjamin Kraus il 20 Set 2023
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;

Più risposte (1)

Adam Danz
Adam Danz il 29 Nov 2018
Modificato: Adam Danz il 3 Gen 2020
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 Commenti
Adam Danz
Adam Danz il 7 Gen 2021
@Daniel, see this link to turn that frown upside down.

Accedi per commentare.

Prodotti


Release

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by