Plot a timeseries in a group?

3 次查看(过去 30 天)
I have an hour of data which is split into 15 mins- so 4 groups of data. Each 15 min period has been calculated differently and I want to show the outcomes of the various analysis methods. So 4 groups with 3 different bar charts in this groups?
I have tried some code but nothing seems to work?? Could anyone help would be very much appreciated.
I am trying to copy the plot attached.
  9 个评论
jonas
jonas 2018-9-11
I removed my last comment and put it in an answer instead, as the result was fairly close to what you are going for. I really hope it helps. If you need more help I will check in tomorrow.
dpb
dpb 2018-9-11
...
...psWc_15_2(1:end-1,1), 0.5*cumsum((psWc_15_2(1:end-1,4)+psWc_15_2(2:end,4)).*diff(psWc_15_2(:,1)))...
...psWc_15_3(1:end-1,1), 0.5*cumsum((psWc_15_3(1:end-1,4)+psWc_15_3(2:end,4)).*diff(psWc_15_3(:,1)))...
...
Do NOT use sequentially-name variables with meta-data stored in the variable names; having all these named variables instead of an array or structure or table is a major factor in the difficulties in doing what is wanted.
Restructure the data first, THEN write a generic analysis and plotting function to process the data and most of the seemingly intractible problems will simply go away.

请先登录,再进行评论。

采纳的回答

jonas
jonas 2018-9-11
You can try this code. I used some messy dynamic field naming to do the plots. Will clean this up tomorrow, but too tired right now.
data=load('matlab_help.mat')
ax1=axes('xscale','log','color','none');
ax2=axes('xscale','log','ycolor','none','color','none');
ax3=axes('xscale','log','ycolor','none','color','none');
ax4=axes('xscale','log','ycolor','none','color','none');
for j=2:4;
axes(ax1);hold on
plot(data.(['psWc_15_',(num2str(j))])(1:end-1,1), 0.5*cumsum((data.(['psWc_15_',(num2str(j))])(1:end-1,4)+data.(['psWc_15_',(num2str(j))])(2:end,4)).*diff(data.(['psWc_15_',(num2str(j))])(:,1))).*86400,'r');
axes(ax2);hold on
plot(data.(['psWc_16_',(num2str(j))])(1:end-1,1), 0.5*cumsum((data.(['psWc_16_',(num2str(j))])(1:end-1,4)+data.(['psWc_16_',(num2str(j))])(2:end,4)).*diff(data.(['psWc_16_',(num2str(j))])(:,1))).*86400,'r');
axes(ax3);hold on
plot(data.(['psWc_17_',(num2str(j))])(1:end-1,1), 0.5*cumsum((data.(['psWc_17_',(num2str(j))])(1:end-1,4)+data.(['psWc_17_',(num2str(j))])(2:end,4)).*diff(data.(['psWc_17_',(num2str(j))])(:,1))).*86400,'r');
axes(ax4);hold on
plot(data.(['psWc_18_',(num2str(j))])(1:end-1,1), 0.5*cumsum((data.(['psWc_18_',(num2str(j))])(1:end-1,4)+data.(['psWc_18_',(num2str(j))])(2:end,4)).*diff(data.(['psWc_18_',(num2str(j))])(:,1))).*86400,'r');
end
set(ax1,'position',[.10 .2 .2 .5])
set(ax2,'position',[.30 .2 .2 .5])
set(ax3,'position',[.50 .2 .2 .5])
set(ax4,'position',[.70 .2 .2 .5])
linkaxes([ax1 ax2 ax3 ax4],'xy')
h=get([ax1 ax2 ax3 ax4],'children')
h=[h{:}];
set(h(1,:),'color','r')
set(h(2,:),'color','b')
set(h(3,:),'color','k')
ax5=axes('ycolor','none','color','none');hold on
set(ax5,'position',[0.1 0.1 0.8 0.1])
axes(ax5)
t=minutes(0):minutes(1):minutes(60);
t.Format='hh:mm';
y=ones(size(t))
plot(t,y,'color','none')
xlim([minutes(0) minutes(60)])
  4 个评论
Rebecca Ellis
Rebecca Ellis 2018-9-12
Just to get the final graph perfect -
ylabel('Flux mmol m^{-2} day^{-1}');
Is not printing the label on the graph.
The how would I set the time to start at 14:00?
and I think the y axis is blurry because it is 10^-5, so would ylim be the best to zoom into the graph to prevent the blurry yaxis? Attached is the image of the output I get.
jonas
jonas 2018-9-12
编辑:jonas 2018-9-12
Please find my attached m-file with some added features. It's a bit messy but it will give you an idea of how to fix those problems. The reason your xticklabel is blurred is because you have two xticklabels on top of eachother, namely 10^-5 and 10^5. They are the first and last values on your axes. I have fixed this issue by moving every second xaxis to the top of the graph. Depending on your preferences, it may be better to remove one of the ticklabels. In order to do so, you just change this line:
set([ax1 ax2 ax3 ax4],'xtick',[1e-5 1 1e5])
to
set([ax1 ax2 ax3 ax4],'xtick',[1e-5 1])
This is actually a fairly fancy graph in my opinion!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by