How can I swith between plots in the same plot window?
20 次查看(过去 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!