How to change XColor and YColor in heatmap plot?

Hi,
I want to change the color of the x- and y-axis in a heatmap plot.
Normally the following code works for a normal plot:
set(gca, 'ZColor','w', 'YColor','w', 'XColor','w') % this line does not work for heatmap
However, the indicated line does not work for heatmap as XColor etc. is not a property that works for heatmap. I get the following error:
The name 'ZColor' is not an accessible property for an instance of class 'matlab.graphics.chart.HeatmapChart'.
My question:
Is there a way to change the color of the X- and Y-axis in a heatmap to white/none?

Risposte (1)

Actually, the code you share does give an error. You have to plot before you set axis color. You could also use the axis off command. Figure background color is white by default.
x = 0:0.1:10;
y = x;
plot(x,y)
axis off
A heatmap is a different type of plot. It does not have axes. Instead, you need to modify the XDisplayLabels and YDisplayLabels. There is no color or size option, so best is to set them equal to NaN. You still need a label for each row/column of the displayed data. Something like this should work.
figure
hm = rand(4);
h=heatmap(hm);
h.XDisplayLabels = nan(size(h.XDisplayData));
h.YDisplayLabels = nan(size(h.YDisplayData));

4 Commenti

Thanks for your reply!
I used my code as follows:
x = 0:0.1:10;
y = x;
figure;
set(gcf,'color','w');
plot(x,y)
set(gca, 'ZColor','w', 'YColor','w', 'XColor','w')
I tried it in the same way for the heatmap and I tried axis off too. But what I want to do is to remove the outside black lines of the heatmap, is that possible?
Cris LaPierre
Cris LaPierre il 12 Dic 2020
Modificato: Cris LaPierre il 12 Dic 2020
Read the full answer.
As for turning off the outside black lines, it may not be possible. See this post.
If you want to show the data without a box, you might consider using imagesc instead. The rows of your matrix correspond to Y, and the columns correspond to X.
Thank you, I will take a look at the implementation of imagesc.

Accedi per commentare.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by