Search code examples
matlab-figure

How can I plot data of multiple days on same plot


I have some data which is collected for 6 days during 8:00AM to 11:00AM. I need to plot all the data on same plot one over other. The way I am doing now:

hold on
 plot(y1,x1,':b*','MarkerEdgeColor','k')
 plot(y2,x2,':r*','MarkerEdgeColor','k')
 plot(y3,x3,':y*','MarkerEdgeColor','k')
 plot(y4,x4,':g*','MarkerEdgeColor','k')
 plot(y5,x5,':c*','MarkerEdgeColor','k')
 plot(y6,x6,':w*','MarkerEdgeColor','k')
 datetick('x','HH:MM:SS')
hold off

where x1 to x6 has y axis data and y1 to y6 have

y(i) = datenum(Year(1:5), Month(1:5), Input_Vector(1:5,2), Input_Vector(1:5,3), Input_Vector(1:5,4), Input_Vector(1:5,5));

When I plot using above, I get the image attached enter image description here

But what I need to find patterns by observing them. So I need to have something one above other with x axis 8:00:00 to 11:00:00

I need something like and I got this by making DAY parameter constant date.

enter image description here


Solution

  • If you want to plot one day over another, then the method you used to make the second graph - discarding/replacing the date part of your datetime - is likely the best way to do it. It matches up nicely with the conceptual question that the graph answers, i.e.: "Is there a link between time of day and duration of journey, regardless of the day it was taken on?"

    If you still want to preserve the day information, you could always perform the multiple plots with different line specs, and have the legend show which line corresponds to which day.

    If the above question - finding a link between time and journey duration - is what you are trying to do, rather than plotting that specific type of graph, I would also try something like this:

    1. Split your day into half hour or quarter hour slots and take the average of all data points in each block. This gives you a single value for each half/quarter hour span.
    2. Plot this as a bar chart with error bars showing standard error (this can be done using bar and errorbars)
    3. If I see anything, try fitting it with an appropriate model and check for goodness of fit. In your case this would probably be a Gaussian model, as your data kinda looks like it peaks around 9:20.