Why doesn't heatmap use the default font?

조회 수: 10 (최근 30일)
O.Hubert
O.Hubert 2018년 8월 6일
편집: Jayanti 2024년 10월 21일
Hello,
I would like to change the font in the axes of my heatmap. I provide a MWE below. I would like the Y-axis and the X-axis to be of the same font as the default and I don't want to manually change that for every plot as that would kill the idea of having a default fontname.
I am using MATLAB R2016a, so inserting 'FontName','Latin Modern Roman' in the heatmap function will not work.
Thank you in advance, Olivier.
% Minimum (Non)-Working Example
Country={'Belgium','France','Germany'};
random_matrix=rand(3,3);
% Set default depending on your MATLAB version
set(0, 'DefaultAxesFontName', 'Latin Modern Roman');
set(0, 'defaultAxesFontName', 'Latin Modern Roman');
% Generate the heatmap
figure('Name','Distance Matrix');heatmap(random_matrix, Country, Country, [], ...
'TickAngle', 45,'ShowAllTicks', true,'Colormap', 'gray','Colorbar', true,'ColorLevels',50);
title(['Distance Matrix']); % title is changed according to new default, but not the rest of the heatmap
% Option suggested in https://nl.mathworks.com/matlabcentral/answers/221149-is-it-not-possible-to-change-every-font-size-on-plots-at-the-same-time
fig = gcf;
set( findall(fig, 'property', 'FontName'), 'FontName', 'Latin Modern Roman') % Not working
  댓글 수: 1
Adam
Adam 2018년 8월 6일
h = heatmap( ... );
h.FontName = '...';
seems to work for me, although it seems to do some odd things to the font colour too in some cases (e.g. setting to Courier).

댓글을 달려면 로그인하십시오.

답변 (1개)

Jayanti
Jayanti 2024년 10월 21일
편집: Jayanti 2024년 10월 21일
Hi Hubert,
Since you are using MATLAB 2016a release, the definition of heatmap is different from later releases. The syntax you are using resembles the “heatmap” function that was introduced in later versions of MATLAB. However, in R2016a, this specific syntax is not supported.
In MATLAB R2016a, you can use the “HeatMap” function instead of heatmap. The “HeatMap” function uses different parameter names, such as “RowLabels” and “ColumnLabels” for specifying labels. Some features like “TickAngle,ShowAllTicks, and “ColorLevels” are not directly available inHeatMap.
You can refer to the below code to create a HeatMap:
HMobj = HeatMap(random_matrix, 'RowLabels', Country, 'ColumnLabels', Country, ...
'Colormap', gray, 'Symmetric', false, 'DisplayRange', 3);
You can also access the documentation link of “HeatMap” by typing the below command in command window of MATLAB.
doc HeatMap
Hope this resolves the issue you are facing.

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by