Hello guys,
Matlab automatically put the x-axis values into x10 format. For example 1.96 x10^7 instead of 1996. This is wrong.
How can I make x-axis values to look like whole number values i.e. 1996, 1998 etc?
Thank you.

回答 (1 件)

Daniel Pollard
Daniel Pollard 2020 年 12 月 15 日

0 投票

This was the top result when I googled "matlab remove scientific notation axis".
From R2015b onwards,
ax = gca;
ax.XRuler.Exponent = 0;

14 件のコメント

Catayoun Lissa Eleonore Azarm
Catayoun Lissa Eleonore Azarm 2020 年 12 月 15 日
this is not working for my case. The x axis still shows wrong numbers
Daniel Pollard
Daniel Pollard 2020 年 12 月 15 日
In your post you said that the numbers show 1.96x10^7 instead of 1996. If these are years, then there's a problem with your dataset as 1.96x10^7 = 1,960,000, not 1996.
Catayoun Lissa Eleonore Azarm
Catayoun Lissa Eleonore Azarm 2020 年 12 月 15 日
ok, so what can i do now? The dataset is given... I think i can set the exponent to 4, then it will be 1996 x10^4, what do you think?
Daniel Pollard
Daniel Pollard 2020 年 12 月 15 日
No, it will be 1960 x10^4, but I think that's ok looking at your data as the temperature seems to oscillate 20 times between 1.96 and 1.98. A quick and dirty fix would be to divide the numbers by 1000, is there any reason you shouldn't do that?
Catayoun Lissa Eleonore Azarm
Catayoun Lissa Eleonore Azarm 2020 年 12 月 15 日
subplot(5,3,1)
date_data_berlin = [all_climate_data{1}.date];
years_data_berlin = round(date_data_berlin/10000);
xlim([1 length(years_data_berlin)])
set(gca,'XTick',round(linspace(1, length(years_data_berlin), 7)))
set(gca,'XTickLabel',years_data_berlin...
(round(linspace(1, length(years_data_berlin), 7))))
plot(date_data_berlin, temperature_data_berlin)
title('Berlin-Tempelhof: Daily temperature data')
ylabel('°C')
Catayoun Lissa Eleonore Azarm
Catayoun Lissa Eleonore Azarm 2020 年 12 月 15 日
you mean dividing years_data_berlin by 1000?
Daniel Pollard
Daniel Pollard 2020 年 12 月 15 日
There's some bizzare things going on there. Why do you divide the date_data by 10000 as you import it? You then overwrite the xlim with 1:length(years), then relabel it with the date_data, manually doing what would have been automatic.
Why not just import the date_data and temperature_data and plot them against each other?
Catayoun Lissa Eleonore Azarm
Catayoun Lissa Eleonore Azarm 2020 年 12 月 15 日
%Compute moving averages of all three temperature data sets
% using movmean. Use a 30-day-average, a one-year-average,
% a 10-y-average, and a 30-y. Make three plot columns with
% 5 rows each for the three climate datasets, containing
% the original daily data, then the four moving averages.
% Make sure to have appropriate descriptions.
% Replace -999 values with NaN and use the nanflag in
% movmean. Using the following combination you can set the
% x-ticks to the years. It's a bit misleading because it
% does not mark the actual start of the year but it will do.
% Just be aware that this is the case!
% date_data = [all_climate_data{i_dataset}.date];
% date_data = [all_climate_data{all_climate_metadata}.date];
% years_data = round(date_data/10000);
% xlim([1 length(years_data)])
% set(gca,'XTick',round(linspace(1, length(years_data), 7)))
% set(gca,'XTickLabel',years_data(round(linspace(1, length(years_data), 7))))
Catayoun Lissa Eleonore Azarm
Catayoun Lissa Eleonore Azarm 2020 年 12 月 15 日
because that was given by the professor.
Catayoun Lissa Eleonore Azarm
Catayoun Lissa Eleonore Azarm 2020 年 12 月 15 日
Catayoun Lissa Eleonore Azarm
Catayoun Lissa Eleonore Azarm 2020 年 12 月 15 日
this is how the plot looks atm. the weird thing is that it labels the axes correctly everywhere but not at daily temp.
Daniel Pollard
Daniel Pollard 2020 年 12 月 15 日
That is strange and suggests that it's an issue with those particular data. Maybe someone else in your class or a professor can help more as they have the data and understand better than me.
Catayoun Lissa Eleonore Azarm
Catayoun Lissa Eleonore Azarm 2020 年 12 月 15 日
ok thank you anyways for your help!
VBBV
VBBV 2020 年 12 月 15 日
編集済み: VBBV 2020 年 12 月 15 日
You have to apply same to
%
subplot(5,3,1)
subplot(5,3,6)
subplot(5,3,11)

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

カテゴリ

タグ

編集済み:

2020 年 12 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by