How to change Heatmap's Grid (Edge) appereance and behavior?

41 ビュー (過去 30 日間)
Luna
Luna 2020 年 3 月 5 日
編集済み: shuyang zhang 2021 年 5 月 31 日
Hi Dear Community,
Today I'm dealing with a heatmap chart to make it look visually beautiful as much as possible. Here below I created some random data with some empty values in it. Later on I realized that the grid color is black and does not change. Also I couldn't find any of these properties: GridAlpha, EdgeAlpha, GridColor, GridLineStyle etc. I was able to control these properties when I use histogram2.
So I thought that if it is a figure and a plot in it, there should be an axis handle for that. I used gca to get axis but it returned me the heatmap object handle itself.
Then I found something interesting and convert the object handle to struct. The Axes field was actually the axis handle. I changed the XAxisLocation to top.
I reached the other properties of the axis but the properties about grid appereance does not work. Eventually, I decided to make grid visible off. But this time it does not look good and hard to understand grid edges.
My goal is make the visualisation plain, with less ink, and understandable.
So my question is how to reduce the GridAlpha on heatmap? Or how can I change its color to white to make it look simple?
% create random data
heatmap_data = randi(20,15,15);
% make some of them empty
heatmap_data(heatmap_data < 15) = NaN;
% create x and y labels
label_names = cellstr(['A':'O']')';
h_fig = figure; % figure handle
h_fig.WindowState = 'maximized';
h_map = heatmap(h_fig,label_names,label_names,heatmap_data,'MissingDataColor',[1 1 1],'ColorbarVisible','off'); % heatmap handle
h_ax = gca; % tried to get axis handle but gives me h_map instead (a heatmap handle)
h_ruler = struct(h_ax); % convert to struct to see undocumented features - meanwhile a warning appears
h_ruler.Axes.XAxisLocation = 'top'; % this actually worked! "h_ruler.Axes" is an Axis Handle.
% but this part does not work:
h_ruler.Axes.GridLineStyle = '--';
h_ruler.Axes.GridAlpha = 0.1;
h_ruler.Axes.GridColor = [0.8510 0.3294 0.1020]; % red color code just for example to show it does not work.
% make grid visible off
h_map.GridVisible = 'off'; % this time heatmap looks bad. It is not easy to understand edges.

採用された回答

Yair Altman
Yair Altman 2020 年 3 月 5 日
There are several alternatives:
  1. Update the grid style to a non-solid line, for example:
hHeatmap = struct(h_map).Heatmap;
hHeatmap.GridLineStyle = ':';
2. Update the grid color to something different than the default, which is uint8([38;38;38;255])
hHeatmap = struct(h_map).Heatmap;
hGrid = struct(hHeatmap).Grid;
hGrid.ColorData = uint8([238;238;238;125]);
For a description of the uint8 4x1 ColorData format, see http://undocumentedmatlab.com/articles/plot-line-transparency-and-color-gradient
  2 件のコメント
Luna
Luna 2020 年 3 月 6 日
Thank you Yair, I was so close to find it! haha :) It definetely works well.
shuyang zhang
shuyang zhang 2021 年 5 月 31 日
編集済み: shuyang zhang 2021 年 5 月 31 日
Thank you Yair, Very USEFUL!!!!!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by