How to remove dates in graph ?
9 次查看(过去 30 天)
显示 更早的评论
I want to plot a graph for two sepcific dates together as one series(i.e 13th Feb and 28th Feb), but as data was taken at same period between 9.30 am to 15.00 pm. I am getting following plot.
In order to get a graph for two dates together I used following code and getting an error.
Date1=NewP{:,"Date"}+NewP{:,"Time"};
Date1.Format='dd/MM/yyyy HH:mm:ss'
NewP.Date=Date1
plot(NewP{:,"Date"},NewP{:,"MeltCushion"})
ax=gca;
ax.XAxis
dstart=NewP{1,"Date"};
dend=NewP{end,'Date'};
xlim([dstart dend]);
ax.XAxis.TickValues=1:10:length(NewP{:,"Date"})
Error using matlab.graphics.axis.decorator.DatetimeRuler/validateTicks
Value must be a vector of increasing datetime values.
Error in matlab.graphics.axis.decorator.DatetimeRuler/setTicksDelegate
How do I remove the linear line between the two dates? I tried xticks for datetime and its showing the same error.
0 个评论
回答(2 个)
dpb
2020-3-20
The error
ax.XAxis.TickValues=1:10:length(NewP{:,"Date"})
Error using matlab.graphics.axis.decorator.DatetimeRuler/validateTicks
Value must be a vector of increasing datetime values.
comes from the use of the value '10' -- the XAxis is a DateTimeRuler object as it says in the error message because you used a datetime as ordinate variable. Presuming the 10 is intended as 10 days you need
ax.XAxis.TickValues=1:days(10):length(NewP{:,"Date"})
instead.
To eliminate the line between the two data sets, the simplest thing to do would be to plot the two sets independently instead of joining them:
figure
plot(P1{:,"Date"},P1{:,"MeltCushion"}
hold on
plot(P2{:,"Date"},P2{:,"MeltCushion"}
where I used P1 and P2 as placeholder variables for your first two variables as used in the first example plot. The only difference is to use the date variable instead of just the time variable as you did there and not joining the two data sets together. You'll also get a color difference automagically, you can set the line color as desired if want them the same.
The problem you'll still have will be that as in your present second graph, the data in each day itself is going to be almost indistinguishable as just a smudge because the time difference between the two dates is so large compared to the time within the day so the linear axis scale isn't appropriate for the detail.
An alternate would be to use an arbitrary day difference between the two and then adjust the tick labels to reflect actual dates if those are important.
2 个评论
dpb
2020-3-21
编辑:dpb
2020-3-22
" I applied the above code, and dates are still far apart."
Yes, that's what I specifically commented on that you've got one day of data for each day of data 10 days apart -- if you plot that on absolute time, then you've got an overall axis that is 12 days long and only 2/12 --> ~17% of it contains the pertinent data...
If the actual day itself isn't of particular importance, you could use just one day duration from the beginning of the first day as the initial date/time of the second which is, in essence the same thing as plotting vs ordinal position except you would have a time axes. Of course, the absolute time wouldn't be the actual days but you could handle that by futzing with the tick labels or otherwise label the two datasets with legend or annotation
You don't say whether you're satisfied by simply using the ordinal position or not...the alternative you might try would be to use the duration from beginning of each data series as the ordinate but add a fixed offset to one of the response variables so that it is plotted directly above the other but doesn't overlay it.
Or, you could consider using subplot(2,1,n) and plot each into a different axis on the same figure.
If the point is just trends, then offsetting one versus the other won't change the slopes; only the magnitude/intercept of a trend line.
darova
2020-3-20
Try this
ix = min(xred) < xblue & xblue < max(xred);
plot(xred,reddata,'r')
hold on
plot(xblue(ix),bluedata(ix),'b')
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Log Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!