Plot a timeseries in a group?

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 Commenti

dpb
dpb il 11 Set 2018
Hard to tell just what you mean to plot here; is it a set of three statistics for each of the four groups? If so, then arrange the 3x4 values by row for the time groups and three columns and call bar with the 'grouped' style. Joy should subsequently ensue...
hold on
semilogx(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))).*86400,'r');
semilogx(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))).*86400,'g');
semilogx(psWc_15_4(1:end-1,1), 0.5*cumsum((psWc_15_4(1:end-1,4)+psWc_15_4(2:end,4)).*diff(psWc_15_4(:,1))).*86400,'b');
semilogx(psWc_16_2(1:end-1,1), 0.5*cumsum((psWc_16_2(1:end-1,4)+psWc_16_2(2:end,4)).*diff(psWc_16_2(:,1))).*86400,'r');
semilogx(psWc_16_3(1:end-1,1), 0.5*cumsum((psWc_16_3(1:end-1,4)+psWc_16_3(2:end,4)).*diff(psWc_16_3(:,1))).*86400,'g');
semilogx(psWc_16_4(1:end-1,1), 0.5*cumsum((psWc_16_4(1:end-1,4)+psWc_16_4(2:end,4)).*diff(psWc_16_4(:,1))).*86400,'b');
semilogx(psWc_17_2(1:end-1,1), 0.5*cumsum((psWc_17_2(1:end-1,4)+psWc_17_2(2:end,4)).*diff(psWc_17_2(:,1))).*86400,'r');
semilogx(psWc_17_3(1:end-1,1), 0.5*cumsum((psWc_17_3(1:end-1,4)+psWc_17_3(2:end,4)).*diff(psWc_17_3(:,1))).*86400,'g');
semilogx(psWc_17_4(1:end-1,1), 0.5*cumsum((psWc_17_4(1:end-1,4)+psWc_17_4(2:end,4)).*diff(psWc_17_4(:,1))).*86400,'b');
semilogx(psWc_18_2(1:end-1,1), 0.5*cumsum((psWc_18_2(1:end-1,4)+psWc_18_2(2:end,4)).*diff(psWc_18_2(:,1))).*86400,'r');
semilogx(psWc_18_3(1:end-1,1), 0.5*cumsum((psWc_18_3(1:end-1,4)+psWc_18_3(2:end,4)).*diff(psWc_18_3(:,1))).*86400,'g');
semilogx(psWc_18_4(1:end-1,1), 0.5*cumsum((psWc_18_4(1:end-1,4)+psWc_18_4(2:end,4)).*diff(psWc_18_4(:,1))).*86400,'b');
set(gca,'Xticklabel',time_labels)
Rebecca Ellis
Rebecca Ellis il 11 Set 2018
Modificato: Rebecca Ellis il 11 Set 2018
This is the code I have written so far - I have 4 variables. The variable names are psWc_15, psWc_16, psWc_17, and psWc_18. and there various attached names depending on there analysis and the coloums within these variables are plotted. The type of plot is a semilog plot.
jonas
jonas il 11 Set 2018
Modificato: jonas il 11 Set 2018
Take a look at your original submission and ask yourself how anyone is supposed to give you adequate help based on that information. After your first reply I still feel the key information is missing, such as the column content of those variables. I mean, what is this???
semilogx(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))).*86400,'r');
You are very unlikely to get a good reply if you limit the information to a minimum. Its also frustrating for those trying to help when small bits of key information is released. It makes it difficult to help with an issue and move on to the next and you end up with 10 incomplete questions that constantly needs updating based on new information.
Perhaps you can attach the data?
Also, perhaps you can finally accept this previous submission ( link )? I remember this question because I spent probably 1-2 hours helping you do basic operations...
I apologies for my lack of explaining the question. I am trying to plot 15 min segments in spectral form calculated in different ways for one hour period. The
semilogx(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))).*86400,'r');
is a way of plotting the spectra. Within each psWc_%d_ has they have columns Frequency = psWc(:,1); Power spectrum = psWc(:,2); cospec = psWc(:,4);
psWc_15 = is the first segment psWc_16 = the next next segment (15 min later) and so on..
I have attached the data - does this explanation make sense? I am extremely sorry that I have problems explaining what I mean, my dyslexia gets in the way sometimes.
jonas
jonas il 11 Set 2018
"does this explanation make sense?"
We are getting there. You are using logscale, but in the attached image the unit is hours? The vector you are plotting against the x-axis ranges from ~0 to ~4 but you say the entire experiment was 1 hour long. What is the unit?
Can you try describing what you want the final graph to look like? I don't see how you can get the same one as you attached, at least not without manipulating the x-data.
I was going to manually rename the x axis or add a second x axis as the time.
I have drawn out and explanation.
The spectra is a cumulative co- spectrum so it is integrating under the curve hense the cumsum. I and others use this plotting script alot. It is now trying to combine a the this script over the timeseries of my selected hour of 15 min segments. Does this help?
jonas
jonas il 11 Set 2018
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.
...
...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.

Accedi per commentare.

 Risposta accettata

jonas
jonas il 11 Set 2018
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 Commenti

This code is great thank you, I understand what you did, this is perfect for what I need and I can implement it for alot of other things. Great thank you so much :) !
jonas
jonas il 12 Set 2018
Modificato: jonas il 12 Set 2018
Always happy to help. Next time, look back on this question and think about what to include in the original submission and I promise that you will get a better and faster answer!
... and dont forget to hit accept
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 il 12 Set 2018
Modificato: jonas il 12 Set 2018
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!

Accedi per commentare.

Più risposte (0)

Categorie

Tag

Richiesto:

il 11 Set 2018

Modificato:

il 12 Set 2018

Community Treasure Hunt

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

Start Hunting!

Translated by