How to control latex TickLabel FontSize?

I'm trying to make a fraction into a tick label. This
set(gca, 'TickLabelInterpreter', 'latex', 'YTickLabel', {'$\frac{a}{b}$'})
puts the fraction where I want it, but it's very very small.
This
set(gca, 'TickLabelInterpreter', 'latex', 'YTickLabel', {'$\frac{a}{b}$'}, 'FontSize',20)
makes the tick label have the size I want, but also increases the title and axes labels, which become way too big.
How can I change the size of the tick label, and nothing else?

 Accepted Answer

Two methods
Set FontSize property
figure()
ax = gca();
set(ax, 'TickLabelInterpreter', 'latex', 'YTickLabel','$\frac{a}{b}$')
ax.YAxis.FontSize = 16;
ylabel('Default label size','FontSize', ax.FontSize)
xlabel('Default label size')
Set FontSize in Latex command
To preserve normalized FontUnit behavior, you can set the fontsize directy in the Latex command. Now, when you change the figure size the title, axis labels, and ticks will resize. However, the ticks may not adjust as they would when you set the axis fontsize property.
figure()
ax = gca();
set(ax, 'TickLabelInterpreter', 'latex', 'YTickLabel', '\fontsize{16}{0}$\frac{a}{b}$')
title('title')
ylabel('xlabel')
xlabel('ylabel')
ax.FontUnits='normalized';

5 Comments

Thank you Adam. That helps, as it increases the size of the fraction, leaving the plot title alone. Unfortunately, it does not solve the problem, as it also increases the yaxis label (to the point it no longer fits). Your image does not show it, as your plot doesn't have labels.
Another hint, if possible?
Adam Danz
Adam Danz on 25 Apr 2023
Edited: Adam Danz on 25 Apr 2023
I updated my answer to show how to get around that.
Tip: Most (all?) text objects have a FontSize property you can set.
Thank you for bearing with me.
That problem seems solved. But that created another problem... I'm finishing my code with
ax.FontUnits='normalized';
as the user may maximize the figure. Now (after implementing your solution above) this still works for the plot title (its font resizes along with the figure), but not for the axis labels or tick label (theirs don't). Is there something else I should be setting as normalized? I've been trying to figure it out, but failed.
See the 2nd solution I added to my answer.
Thank you Adam for your continued assistance, that solved my problem.

Sign in to comment.

More Answers (0)

Products

Asked:

on 25 Apr 2023

Commented:

on 28 Apr 2023

Community Treasure Hunt

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

Start Hunting!