How to change the fontsize of labels not axsis.

28 views (last 30 days)
I want to change the fontsize of labels of x and y.
But if I change the font size of the label, the size of the numerical value on the axis will also change.
Is there good way?
Theta_Theory = linspace(-3.14, -4.71, 100);
Velocity_Theory = linspace(-100,0,100);
x1 = sin(Theta_Theory);
y1 = -cos(Theta_Theory);
T = sqrt(2*abs(y1)/9.8);
z = x1 + abs(Velocity_Theory).*T.';
z = -abs(z - target);
x = Theta_Theory;
y = Velocity_Theory;
minx = min(x);
maxx = max(x);
miny = min(y);
maxy = max(y);
meanValue = mean(z);
heatMapImage = meanValue .* zeros(100,100);
for k = 1 :100
column = round( (x(k) - minx) * 100 / (maxx-minx) ) + 1;
row = round( (y(k) - miny) * 100 / (maxy-miny) ) + 1;
heatMapImage(row, column) = z(k);
end
figure(1)
hh = heatmap(x,y,z,'Fontname','Times New Roman','ColorbarVisible', 'on','GridVisible','off');
h = gca;
%.xlabel('Angular[rad]');
%h.ylabel('Angular Velocity[m]');
h.FontSize = 8; % here is problem.
h.FontName = 'Times New Roman';
h.xlabel('Angular(rad)');
h.ylabel('AngularVelocity[m/s^2]');
colormap hot

Answers (2)

Voss
Voss on 1 Nov 2021
Try replacing those four lines of code with the following:
h.FontName = 'Times New Roman';
h.XLabel.String = 'Angular(rad)';
h.YLabel.String = 'AngularVelocity[m/s^2]';
h.XLabel.FontSize = 8;
h.YLabel.FontSize = 8;
  2 Comments
ryunosuke tazawa
ryunosuke tazawa on 2 Nov 2021
The error happed.
Dot indexes are not supported for variables of this type and assignments cannot be made.
Should I do?
Voss
Voss on 2 Nov 2021
make sure h is still your axes when those lines run

Sign in to comment.


Jan
Jan on 1 Nov 2021
h = gca;
h.FontSize = 8; % here is problem.
This changes the font size of the complete axes object. If you want to change the font size of the x-label only, do not touch the font size of the axes, but of the XLabel:
axesH = axes;
plot(axesH, 1:10);
axesH.XLabel.String = 'X label';
axesH.XLabel.FontSize = 20;

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!