How can I change the font size of the tick labels without changing the font size of the axis labels?

7 ビュー (過去 30 日間)
I would like to change the font size of the tick labels of the x-axis of my graph but I don't want any other font size in the y axis to be changed, i.e. I don't want to change the font size of the x-axis label, the y-axis label or the tick labels in the y-axis.

回答 (1 件)

Marc Jakobi
Marc Jakobi 2016 年 10 月 7 日
編集済み: Marc Jakobi 2016 年 10 月 7 日
xl = get(gca,'XLabel');
xlFontSize = get(xl,'FontSize');
xAX = get(gca,'XAxis');
set(xAX,'FontSize', Fontsize)
set(xl, 'FontSize', xlFontSize);
Note: You have to change the xlabel FontSize back after changing the XAxis FontSize
  2 件のコメント
Victor Lejona
Victor Lejona 2016 年 10 月 7 日
I get this:
Error using set
Value must be a handle
Marc Jakobi
Marc Jakobi 2016 年 10 月 7 日
編集済み: Marc Jakobi 2016 年 10 月 7 日
did you type everything correctly?
xAX and xl should be handles if you run the code
xl = get(gca,'XLabel');
xAX = get(gca,'XAxis');
before using set() on them.
Here's a full example:
axes;
xlabel('test')
Fontsize = 18;
xl = get(gca,'XLabel');
xlFontSize = get(xl,'FontSize');
xAX = get(gca,'XAxis');
set(xAX,'FontSize', Fontsize)
set(xl, 'FontSize', xlFontSize);
Copy/paste this into your workspace. If it runs currectly, you must have mistyped something. If it doesn't, "get(gca,'XAxis')" may not be supported by your Matlab version.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGrid Lines, Tick Values, and Labels についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by