How can I enlarge a subplot in a 'new' figure window by just clicking any of the subplot?
8 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Samayochita
2025 年 3 月 26 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Subplots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!