Subplot in PlotButton Callback: Can a subplot be incorporated into the code of a plot button?
Show older comments
I am tryin to get several plots into one figure using the plot button callback. In the past, it would be easy to get several plots on figure by doing something like
subplot(3,1,1)
plot(angle1, velocity1)
title(' ')
ylabel(' ')
subplot(3,1,2)
plot(angle2, velocity2)
title(' ')
ylabel(' ')
subplot(3,1,3)
plot(angle3, velocity3)
title('')
ylabel(' ')
xlabel(' ')
pause;
Is this possible using a push button?
Answers (2)
Matt Fig
on 10 Mar 2011
I think you must mean that you want a new subplot with each button press, is that correct? If so, do you want to limit the number of subplots created? You could do something like this for the pushbutton callback:
function [] = pb_callback(varargin)
N = get(gcbo,'userdata') % Use pushbutton handle.
if isempty(N) % You could also initialize this in createfcn.
N = 1;
elseif N>4 % Limit the user to 4 subplots.
disp('Maximum number of subplots already reached')
return
end
subplot(2,2,N)
plot(....) % Plot your stuff.
set(gcbo,'userdata',N+1); % Update the userdata.
Note that you could store the subplot count in guidata or wherever you want.
Walter Roberson
on 10 Mar 2011
0 votes
Carlo, subplot() needs to know the number of plots ahead of time in order to size each one correctly. If you know the number of plots, then Matt Fig's code should be useful for you. If you do not know the number ahead of time, then using subplot() for this purpose would be tricky, as you would have to predict the area that subplot would want to allocate for the new plot and then you have to shrink and move your existing plots to make room before you do the subplot() [subplot will delete any existing axes that the new axes would overlay by even a single pixel.]
There are other possibilities, such as a using a scrollable pane of plots. I believe there is a Matlab File Exchange (FEX) contribution that implements scrollable panes of plots, but I am not sure if you need to specify the total area ahead of time for that contribution.
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!