필터 지우기
필터 지우기

StackedPlot with separate events

조회 수: 36 (최근 30일)
Alex Newell
Alex Newell 2024년 7월 2일 16:08
댓글: Alex Newell 2024년 7월 2일 22:25
I'd like to make a stacked plot with each plot showing different events (each plot's own events only). How could I fix this code to show only the proper data's corresponding events? (apologies for my clumsy coding)
%make timetable
times=[1, 2, 5]';
s=seconds(times);
variable=[3, 4, 5]';
T=table(s,variable);
TT=table2timetable(T);
%makes event table
EventTime = seconds(4);
lengths = seconds(1);
Events = eventtable(EventTime,EventLengths=lengths);
%Assign event table to time table
TT.Properties.Events=Events;
%make timetable
variable2=[6, 8, 9]';
T2=table(s,variable2);
TT2=table2timetable(T2);
%makes event table
EventTime2 = seconds(1);
lengths2 = seconds(1);
Events2 = eventtable(EventTime2,EventLengths=lengths2);
%Assign event table2 to time table2
TT2.Properties.Events=Events2;
stackedplot(TT,TT2)
  댓글 수: 2
Noah Prisament
Noah Prisament 2024년 7월 2일 19:26
이동: Voss 2024년 7월 2일 19:28
Hi Alex, I have submitted an Enhancement Request on your behalf to the relevant development team to support this functionality in a future update or release of MATLAB.
Alex Newell
Alex Newell 2024년 7월 2일 22:25
Awesome, thank you!

댓글을 달려면 로그인하십시오.

답변 (1개)

Voss
Voss 2024년 7월 2일 16:50
Maybe something like this is good enough:
%make timetable
times=[1, 2, 5]';
s=seconds(times);
variable=[3, 4, 5]';
T=table(s,variable);
TT=table2timetable(T);
%makes event table
EventTime = seconds(4);
lengths = seconds(1);
Events = eventtable(EventTime,EventLengths=lengths);
%Assign event table to time table
TT.Properties.Events=Events;
%make timetable
variable2=[6, 8, 9]';
T2=table(s,variable2);
TT2=table2timetable(T2);
%makes event table
EventTime2 = seconds(1);
lengths2 = seconds(1);
Events2 = eventtable(EventTime2,EventLengths=lengths2);
%Assign event table2 to time table2
TT2.Properties.Events=Events2;
f = figure();
tl = tiledlayout(f,2,1);
ax = gobjects(1,2);
h = gobjects(1,2);
col = colororder(f);
ax(1) = nexttile(tl);
h(1) = plot(TT.s,TT.variable,'Color',col(1,:));
xregion(ax(1),Events.Time,Events.Time+Events.EventLengths);
ylabel(ax(1),'variable','Rotation',0);
ax(1).Box = 'off';
ax(1).XAxis.Visible = 'off';
ax(2) = nexttile(tl);
h(2) = plot(TT2.s,TT2.variable2,'Color',col(2,:));
xregion(ax(2),Events2.Time,Events2.Time+Events2.EventLengths);
ylabel(ax(2),'variable2','Rotation',0);
xlabel(ax(2),'s');
ax(2).Box = 'off';
legend(h,{'TT','TT2'},'Location','NorthOutside','Orientation','horizontal')
linkaxes(ax,'x')
  댓글 수: 3
Voss
Voss 2024년 7월 2일 19:36
Unfortunately, MathWorks doesn't allow us much customization of stackedplots at the present time. Maybe someone else can share a workaround using a stackedplot.
Note that in my answer, all the axes are linked in the 'x' dimension (linkaxes(ax,'x')), so when you zoom/pan on one axes, the others will update automatically. It may not be as useful as the "linked datatip" you'd get in a stackedplot, but it may be of some use.
Alex Newell
Alex Newell 2024년 7월 2일 22:25
Ok, thanks a lot!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Object Programming에 대해 자세히 알아보기

제품


릴리스

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by