How can I enlarge a subplot in a 'new' figure window by just clicking any of the subplot?
    8 vues (au cours des 30 derniers jours)
  
       Afficher commentaires plus anciens
    
Lets say, I have 2 X 2 subplot grid in a single figure window. When the 4 subplots are shown in a single figure, I want to be able to click on any of the individual subplot, that should open that particular graph in a new figure window (eesentially, enlarging the subplot into a new figure). Is there a way to do this?
Thank You.
0 commentaires
Réponses (1)
  Samayochita
 le 26 Mar 2025
        Hi Ajeya,
The required functionality can be achieved in MATLAB by using the “ButtonDownFcn” property of each subplot which allows you to define a callback function that is executed when you click on the subplot. In the callback function, you can create a new figure and plot the data from the selected subplot.
Here is how one could implement this:
1) Create a 2x2 grid of subplots.
figure;
for i = 1:4
    subplot(2, 2, i);
    plot(rand(10, 1)); 
    title(['Subplot ' num2str(i)]);
    % Set the ButtonDownFcn property for each subplot
    ax = gca; % Get the current axes
    ax.ButtonDownFcn = @(src, event)enlargePlot(src);
end
2) Define a callback function “enlargePlot” that will be called when a subplot is clicked. This function will open a new figure and copy the contents of the clicked subplot to the new figure.
function enlargePlot(src)
% Create a new figure
newFig = figure;
% Copy the contents of the clicked subplot to the new figure
newAx = copyobj(src, newFig);
% Adjust the position to fill the new figure
set(newAx, 'Position', get(0, 'DefaultAxesPosition'));
end
For more information on the “ButtonDownFcn” property, please refer to the following documentation:
I hope this helps.
0 commentaires
Voir également
Catégories
				En savoir plus sur Subplots dans Help Center et File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

