Why doesn't heatmap use the default font?
5 views (last 30 days)
Show older comments
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 Comment
Adam
on 6 Aug 2018
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).
Answers (1)
Jayanti
on 21 Oct 2024
Edited: Jayanti
on 21 Oct 2024
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 in“HeatMap”.
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.
0 Comments
See Also
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!