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?
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?
%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)

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

편집:

2020년 12월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by