Plot a timeseries in a group?
4 ビュー (過去 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
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
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
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 件のコメント
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 Center および File Exchange で Labels and Annotations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!