change Axis ticklabel font size

304 views (last 30 days)
MINA
MINA on 7 Mar 2016
Commented: BK Shouharda on 28 Jun 2021
I am trying to change the font size of Xticklabel by this code
a = get(gca,'XTickLabel');
set(gca,'XTickLabel',a,'fontsize',12,'FontWeight','bold')
in a figure where I have 6 subplots and I do this for each subplot separately. However when I get my figure the order of the numbers on the axis are wrong, for example on X axis it shows: [0 500 1000 0 500 1000]. I realized that sometimes if I only set one axis (either X or Y) it would automatically apply on both axis and I don't get this error. But I tried that on each subplot and still doesn't work.
Could you please help me what I can do to solve this issue?

Answers (2)

Alexander Cranney
Alexander Cranney on 3 Oct 2018
Edited: Alexander Cranney on 3 Oct 2018
I was having this same issue. It's easier in 2015B, but some users of my plotting GUI were using 2015A, so I had to figure out how to make it work in 2015A. Try the below code:
a = get(gca,'XTickLabel');
set(gca,'XTickLabel',a,'fontsize',12,'FontWeight','bold')
set(gca,'XTickLabelMode','auto')

Walter Roberson
Walter Roberson on 7 Mar 2016
Every subplot is an axes by itself. Axes do not "contain" subplots: each subplot is a full independent axes that happens to be positioned nicely relative to other axes.
Up to R2014a, the axes fontname property affects the x, y, and z axes at the same time and they cannot be varied independently. The situation for R2014b is a bit confused. As of R2015a, there is are XAxis, YAxis, and YAxis components of axes that can have their FontName properties set independently.
Is it possible that you are using plotyy() or plotxx() ? Those create additional axes that are "below" what is obvious. If you were to set the properties of one of the two plotyy or plotxx axes without setting the other appropriately, you could end up with multiple labels showing up. If you are using plotyy only one of the two x axes should have its XTick set or else you will get duplicate ticks. If you are using plotxx only one of the two y axes should have its YTick set or else you will get duplicate ticks.

Community Treasure Hunt

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

Start Hunting!