thank you both for your answers. Actually I was wrong. Plotxx and the methods you suggested work with the 2016b pre-release. Problem solved!
Multiple x axes with datetime time series
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I am trying to plot a couple of data sets (for example aircraft altitude and temperature or pressure) as a function of time and I would like to use two different x axes. One x-axis is UTC seconds (numeric values) and the other is a datetime variable (created using the Matlab datetime function). None of the solutions I found (e.g. plotxx, or line plots) seem to work with datetime variables. I would be grateful for any suggestions/solutions. (Plotting two different plots is one solution but not desirable).
0 commentaires
Réponse acceptée
Plus de réponses (2)
dpb
le 14 Sep 2016
It's not hard to create the second axes object; see the example under Graphics Objects on Using Mulitple X- and Y-Axes
The gist of the problem is
hL(1)=plot(time,Firstyvalues); % the first line creates an axes automagically
hAx(1)=gca; % get that one's handle
hAx(2)=axes('Position',get(hAx(1),'Position'),... % make second axes on top of first
'XAxisLocation','top',...
'Color','none',...
'XColor','k','YColor','k');
hL(2)=plot(hAx(2),UTCtime,Secondyvalues); % now the second goes in that axes
I don't have recent-enough release to be able to test the datetime object behavior; I'm presuming if the format property is set properly the second time will show up correctly...
Note that other graphics routines beyond plot haven't been updated to accept datetime classes; you have to revert to doubles to use line or others (or, I presume, to use set to update x/y-data directly).
But, that should get a start...
Oh, or use plotyy and then move the RH x-axes to 'top' may be an alternate route.
0 commentaires
Peter Perkins
le 15 Sep 2016
plotyy will work for plotting against datetimes (with some rough edges prior to R2016b), but it sounds like you want to overlay a plot against a datetime with one against a posix time. It's not clear to me what relationship those two time vectors have to each other, or what you want the plot to look like. I imagine you'll need two different axes for the two different "x" types. That's what dpb has suggested.
I think dpb's suggestion might work with some effort, depending on what version of MATLAB you're using (the newest R2016b release has improvements to datetime plotting in general). It looks like you'd need to the axis properties after making the second plot rather than before, and you'll have to reconcile the two different y axes.
1 commentaire
dpb
le 15 Sep 2016
datetime is exceedingly complex and not having a recent-enough release (I really should try again and see if performance has improved enough to run on this old machine but that's an exercise for another time (so to speak :) ) I can't figure out even half the nuances, but it accepts 'posix' time as an input; I'd presume that would be an output format as well??? What does 'preserveinput' do if the input x is 'posixtime'?
If that isn't automagic, then it would seem that it's simply a differential time from the POSIX UTC time zero excepting for the nitty details that may not make the two consistent...excepting the logic has to be in there somewhere to accept the input. Oh, what tangled webs we weave...
Voir également
Catégories
En savoir plus sur Two y-axis dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!