Adding units on my axis

I need to add degrees on my ylabel and percentage on my xlabel as per picture. The code i used only adds percentage on my ticks instead of my labels. How can i do that without compromising my entire code. Afterwards i have to collect statistics and their results needs to show those units as well e.g Mean humidity in %

回答 (1 件)

Walter Roberson
Walter Roberson 2023 年 10 月 26 日

0 投票

x = 0:10:100;
y = rand(size(x));
plot(x, y)
xtickformat('%.1f%%')

5 件のコメント

Martha
Martha 2023 年 10 月 26 日
My ticks should not have any unit on then. I need for instance the ylabel is named Temperature(degree celsius) and xlabel is Humidity(%)
Walter Roberson
Walter Roberson 2023 年 10 月 26 日
x = 0:10:100;
y = randn(size(x));
plot(x, y)
xlabel('Humidity (%)')
ylabel(sprintf('Temperature (\xb0 C)'), 'interpreter', 'none')
Martha
Martha 2023 年 10 月 26 日
Thank you, the labels are now okay but the results yielded dont have those units
Walter Roberson
Walter Roberson 2023 年 10 月 26 日
When you asked the question, you accidentally omitted the picture, so I do not have anything to compare against.
Also we do not have your data values, and we do not know how you computed them, so we have no idea what you mean by the results yeilded don't have those units. If your temperature values are in (say) Rankine, then convert them to Celcius before plotting.
Adam Danz
Adam Danz 2023 年 10 月 26 日
Another option starting in MATLAB R2023b is to use the secondary label properties to indicate units.
x = 0:10:100;
y = randn(size(x));
plot(x, y)
xlabel('Humidity')
ylabel('Temperature')
xsecondarylabel('(%)')
ysecondarylabel(['(',char(176),'C)'])

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

カテゴリ

製品

リリース

R2023b

タグ

質問済み:

2023 年 10 月 26 日

コメント済み:

2023 年 10 月 26 日

Community Treasure Hunt

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

Start Hunting!

Translated by