Independent XTickLabel and YTickLabel font sizes
36 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Is it possible to set the font size of y-tick marks independently of the font size of the x-tick marks, ylabel and xlabel?
When I use:
set(gca,'YTick',[-pi 0 pi], 'YTickLabel', {'-\pi','0','\pi'}, 'fontsize', 18);
it sets the fonts size for all labels to the same size. Is there a standard MATLAB function to do this?
0 commentaires
Réponse acceptée
Steven Lord
le 2 Août 2016
The documentation includes examples that use the numeric rulers (introduced in release R2015b) that are part of the axes to do this type of customization. You can also change the properties of the objects stored in the XLabel and YLabel properties of the axes.
% Sample data
x = -1:0.01:1;
y = 3*asin(x);
% Plot it and retrieve the handles of the objects we're going to manipulate
h = plot(x, y);
yL = ylabel('Abracadabra');
xL = xlabel('For demonstration purposes only', 'Color', 'r');
ax = ancestor(h, 'axes');
yrule = ax.YAxis;
% Change properties of the axes
ax.YTick = [-pi 0 pi];
ax.YTickLabel = {'-\pi','0','\pi'};
% Change properties of the ruler
yrule.FontSize = 18;
% Change properties of the label
yL.FontSize = 8;
Some of the manipulation I did (in particular changing the YTick and YTickLabel properties of the axes) I could have done via several of the objects as well. But in order to change the font size of the X and Y axes independently I need the ruler. Changing the axes FontSize using ax would change all of the X tick labels, X label, Y tick labels, and Y label.
2 commentaires
Steven Lord
le 2 Août 2016
The plot function returns a two element vector of handles to lines. When you use that vector of handles as input to ancestor it returns a two element cell array where each element contains the axes ancestor of the corresponding line from the vector. Since they're in the same axes, just ask for the axes ancestor of one of the lines.
ax = ancestor(h(1), 'axes');
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Axis Labels dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!