I have plotted this graph with the following code :
plot(0:23,ozone_values(:,1),0:23,ozone_values(:,2),0:23,ozone_values(:,3),0:23,ozone_values(:,4),0:23,ozone_values(:,5),0:23,ozone_values(:,6),'LineWidth',1.3)
xlabel('Hour')
ylabel('Concentration of ozone (in ug/cm)')
title('Diurnal variation of Ozone')
legend('Jan','Feb','Mar','Apr','May','Jun')
set(gca, 'Xtick',(0:6:23))
xlim([0 23])
So my problem is that I want to change the xtick labels, given is in utc and i want to covert it in ist. For data sets i have done that part but i could not manipulate the xtick values. Those ticks will be 5:30,11:30,17:30 and 23:30 instead of 0,6,12 and 18. How can i do this particular change?

 採用された回答

Cris LaPierre
Cris LaPierre 2020 年 12 月 8 日

0 投票

First, let's clarify that you want to modify the xtick values, not ytick.
The best approach is to have your x values be datetimes or durations. They your xticks will be time values. You can then set the values using xtick and their appearance using xtickformat.
% Create x, y data
x = (duration(0,30,0) + hours(0:23))'; % durations - no date associated with it
y=rand(24,6);
plot(x,y,'LineWidth',1.3)
xlabel('Hour')
ylabel('Concentration of ozone (in ug/cm)')
title('Diurnal variation of Ozone')
legend('Jan','Feb','Mar','Apr','May','Jun')
% Format and place ticks as desired
xtickformat("hh:mm")
xticks(hours([5.5 11.5 17.5 23.5]))

5 件のコメント

SWARNENDU PAL
SWARNENDU PAL 2020 年 12 月 8 日
thank you for your answer. But 0,6,12,18 should be replaced by 5:30,11:30,17:30 and 23:30. Sorry i forget to mention that. So basically 5:30,11:30,17:30 and 23:30 these values will be overwritten. Thank you once again
Cris LaPierre
Cris LaPierre 2020 年 12 月 8 日
You have 24 data points in Y for each month. What should their corresponding x-values be (for all 24)?
SWARNENDU PAL
SWARNENDU PAL 2020 年 12 月 9 日
those will be hour. But in my data set those time are given in UTC time zone. So I have to shift my time as per IST time zone. So after tried many thing i have done this,the code is given below :
xticks([0 6 12 18])
xticklabels({'05:30','11:30','17:30','23:30'})
this code will replace 0,6,12,18 by 5:30,11:30,17:30,23:30.Thanks for your support sir.
Cris LaPierre
Cris LaPierre 2020 年 12 月 9 日
編集済み: Cris LaPierre 2020 年 12 月 9 日
Ok, sorry for my misunderstanding.
Yes, changing xlabels is one way, but in this situation, I think it is better to update the underlying data and use xticks.
% Create x, y data
xUTC = hours(0:23)'; % durations - no date associated with it
xIST = xUTC + hours(5.5);
y=rand(24,6);
plot(xIST,y,'LineWidth',1.3)
xlabel('Hour')
ylabel('Concentration of ozone (in ug/cm)')
title('Diurnal variation of Ozone')
legend('Jan','Feb','Mar','Apr','May','Jun')
% Format and place ticks as desired
xtickformat("hh:mm")
xticks(xIST(1:6:end))
SWARNENDU PAL
SWARNENDU PAL 2020 年 12 月 9 日
Thank you sir.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by