shift x axis to plot daytime hours before nighttime hours
2 次查看(过去 30 天)
显示 更早的评论
I have a plot where the x axis is the hour of the day. Right now the xaxis starts at 0 and ends at 24. Instead, I want to plot the daytime hours before the nighttime hours so that it starts at x=8 and ends at x=7 so that I can view all the nighttime data together. Can someone tell me how to set up the plot this way?
Thank you!
This is my code right now:
f1=figure(1)
hold on; box on;
yyaxis left
yline(0)
bar(1:24,mfbin,'facecolor',gray);
errorbar(1:24,mfbin,sdfbin,'k.','linewidth',e)
ylabel('Filtered Flux (mmol/m^2/h)')
ylim([-70 70])
yyaxis right
plot(1:24,mMPARbin,'b.','markersize',30);
yline(100,'b')
% errorbar(1:24,mMPARbin,sdMPARbin,'k.','linewidth',e);
ylabel('PAR')
ylim([-1000 1000])
xlim([0 24])
set(gca,'fontsize',18)
ax=gca;
ax.YAxis(1).Color='k'
ax.YAxis(2).Color='b'
0 个评论
采纳的回答
Walter Roberson
2020-8-16
That only makes sense if the data is valid for 24 hours starting at 8am, not if the data is for one particular calendar day.
If the data is valid for 24 hours, then take
H = datetime('today','Format', 'HH') + hours(8:24+7);
errorbar(H, circshift(mfbin,-7), circshift(sdfbin,-7), 'k.', 'linewidth', e)
and similar.
8 个评论
Walter Roberson
2020-8-18
It appears that the underlying graphics objects used to create errorbars do not permit non-numeric x coordinates.
You can use xticklabels() to cause the output labels to be whatever you want, so you could use "hours since 08:00" as your x but label it as appropriate. The difficulty with that approach is that it does not adjust data cursors. You can program data cursors to hide the underlying values if need be... but it is easier if you just do not support data cursors.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!