How to plot discrete data in a stackedplot
조회 수: 12 (최근 30일)
이전 댓글 표시
I'd like to plot timetable data consisting of discrete data (e.g. boolean, enumerations) in a stackedplot (common time x-axis).
In order to plot discrete data there are functions like stairs which supress (?) linear interpolation and plot like interpolation method "zoh".
Is it possible to change the interpolation of stackedplot (to "zoh") or a similar plot with time cursor (lets call it stackedstairs) ? Or do I have to use multiple subplots with stairs and link the x-axis?
댓글 수: 0
채택된 답변
dpb
2021년 3월 29일
편집: dpb
2021년 3월 29일
There's a 'PlotType' property in the stackedplot object that has the option for 'stairs' -- none of the previous gyrations are needed, simply
hSP=stackedplot(tbl,vars); % stacked plot for starters
set(hSP.LineProperties,{'PlotType'},{'stairs'})
Have to use set since there is an array of axes and the dot notation can't deal with arrays.
댓글 수: 0
추가 답변 (1개)
dpb
2021년 3월 26일
편집: dpb
2021년 3월 26일
You can get creative and use stackedplot to create the axes for you, and then go "handle-diving" to find and modify the content of the underlying axes...
I used one of the examples for stackedplot as a start point --
tbl = readtable('patients.xls'); % some sample data
vars={'Height','Weight','Systolic','Diastolic'}; % pick the variables
hSP=stackedplot(tbl,vars); % stacked plot for starters
hAx=flip(hSP.NodeChildren(numel(vars)+1:end)); % get the axes handles
for i=1:numel(hAx) % for each axes (same as numel(vars))
hold(hAx(i),'on') % set hold on for each axes to keep other properties unchanged
hL=hAx(i).Children; % get existing line handle
delete(hL); % delete that line
hSL(i)=stairs(hAx(i),tbl.(vars{i})); % replace with stairs line
end
Above yields
Introducing a function handle for the plot function into stackedplot seems worthwhile enhancmenet request.
NOTA BENE: The stackedplot object hides the axes handles in the undocumented and hidden NodeChildren property. Another case IMO of TMW getting far too clever in their penchant to create opaque objects.
Inspection showed the Axes are the last elements in the array and are stored in obverse order of their creation; this is a pretty common (universal?) order in such case; one can tell which is which by inspection of the .Position property for the bottom location of the axes. Remember the position 4-vector is [left bottom width height]
댓글 수: 11
dpb
2021년 3월 29일
편집: dpb
2021년 3월 29일
" I just set the linestyle to none after the loop."
You can do that first instead of last to make them not show. Of course, that leaves the old data in place as well, but "any port in a storm!" when it comes to workarounds.
However, see the alternate Answer for the REAL workaround -- but your above reference got me looking more deeply at the stackedplot object and turns out TMW had it built-in all along -- and it is even documented in an example, I just didn't look at all the examples.
참고 항목
카테고리
Help Center 및 File Exchange에서 Graphics Object Programming에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!