How can I swith between plots in the same plot window?
19 ビュー (過去 30 日間)
古いコメントを表示
I have a time-lapse matrix. Each column is a region of interest (Roi) and each row is the time point value. I need to quickly visualize each trace individually. Is there a way to plot all the traces at the same time but have only one at a time selected for visualization so I can move quickly through the traces just by clicking the up/down buttons to move through selections?
0 件のコメント
採用された回答
Rik
2018 年 3 月 24 日
編集済み: Rik
2018 年 3 月 25 日
You can plot all the lines and toggle the visibility with the KeyPressFcn of the figure, which sets the Visible property of the line objects that plot returns.
Edit: see an example below
f=figure(1);clf(1)
h=plot(rand(4,2));axis([1 3 0 1])
handles=struct('f',f,'h',h);
handles.visible_index=1;%keep track of which plot is selected
set(h,'Visible','off');
set(h(handles.visible_index),'Visible','on');
guidata(f,handles)
set(f,'KeyPressFcn',@SetVisibility)
function SetVisibility(hObject,eventdata)
switch eventdata.Key
case {'uparrow','up'}
direction=1;
case {'downarrow','down'}
direction=-1;
otherwise
return
end
handles=guidata(hObject);
%set the old plot to invisible
set(handles.h(handles.visible_index),'Visible','off');
%find the new index to be set
handles.visible_index=mod(handles.visible_index+direction,length(handles.h));
if handles.visible_index==0,handles.visible_index=length(handles.h);end
%set the new plot to visible
set(handles.h(handles.visible_index),'Visible','on');
%optional: set the title to the index value
title(sprintf('selected plot: %d',handles.visible_index))
guidata(hObject,handles)
end
4 件のコメント
Rik
2018 年 4 月 20 日
Just as a note for future reference (in response to your email): I am receiving notifications, although I did choose to disable email notifications. That way I can keep track of the questions that get updates, but only when I have time to actually reply.
The code below is the adapted version. If you make sure h is a matrix where each row should be displayed simultaneously, this will do that for you. Don't forget to explicitly code a range for the axes (like I did with axis([1 4 0 1]) below). This will prevent the axes to jump around when you hide plots.
f=figure(1);clf(1) y1=rand(4,2); y2=rand(4,2); y3=rand(4,2); x=1:4; h=plot(x,y1,'y',x,y2,'k',x,y3,'r');
h=reshape(h,2,3);
axis([1 4 0 1]) handles=struct('f',f,'h',h); handles.visible_index=1;%keep track of which plot is selected set(h,'Visible','off'); set(h(handles.visible_index,:),'Visible','on'); guidata(f,handles) set(f,'KeyPressFcn',@SetVisibility) function SetVisibility(hObject,eventdata) switch eventdata.Key case {'uparrow','up'} direction=1; case {'downarrow','down'} direction=-1; otherwise return end handles=guidata(hObject); %set the old plot to invisible set(handles.h(handles.visible_index,:),'Visible','off'); %find the new index to be set handles.visible_index=mod(handles.visible_index+direction,size(handles.h,1)); if handles.visible_index==0,handles.visible_index=size(handles.h,1);end %set the new plot to visible set(handles.h(handles.visible_index,:),'Visible','on'); %optional: set the title to the index value title(sprintf('selected plot: %d',handles.visible_index)) guidata(hObject,handles) end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Line Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!