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 (최근 30일)
이전 댓글 표시
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
채택된 답변
추가 답변 (2개)
dpb
2016년 9월 14일
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
Peter Perkins
2016년 9월 15일
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
dpb
2016년 9월 15일
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...
참고 항목
카테고리
Help Center 및 File Exchange에서 Two y-axis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!