Can subplots axes limits be edited after the plot has been created and closed, without the Property Editor?

12 ビュー (過去 30 日間)
I've generated several figures (each of which contain 2 stacked subplots with a since wave in each subplot), using the following code;
% Generate some data
x = linspace(0,10);
y1 = sin(x);
y2 = sin(5*x);
% Create a figure with 2 stacked subplots; a sine wave in each one.
Figure('Name', 'Test Figure', 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
h(1) = subplot('Position', [0.05 0.5168 0.8316 0.415]);
plot(x, y1);
h(2) = subplot('Position', [0.05 0.01 0.8316 0.36700]);
plot(x, y1);
% Save the figure and variables, then close the figure
savefig(gcf, 'A_SubplotTest.fig', 'compact');
save('A_SubplotTestVariables.mat');
close;
I'm not sure how to get MATLAB to recognize the subplot axes for the upper and lower subplots. But I'd like to edit the axes of the upper subplot and just the x-axis of the lower subplot without using the property editor.
Can this be done?
Thank you.
  3 件のコメント
Brandon  Madsen
Brandon Madsen 2018 年 1 月 25 日
As far as I know, there is no way to edit a file that is not opened. That sort of gets to the very definition of "opened."
There is definitely a way to edit the axes of individual subplots either before closing the figure or after re-opening it, but unless you tell us what kind of editing you're trying to do it will be hard to help you with that.
Brad
Brad 2018 年 1 月 25 日
Rik/Brandon: After digging a little more, it appears you are correct - the handles go away once the figures are closed. So even after re-opening the figure, it doesn't appear to help. Brandon, you mention there is definitely a way to edit the axes of individual subplots either before closing the figure or after re-opening it. Can this be done without using the property editor? If so, all I'm trying to do is edit the axes limits of the upper subplot, and the x-axis (only) limits of the lower subplot.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2018 年 1 月 25 日
fig = openfig('A_SubplotTest.fig');
h = findobj(fig, 'type', 'axes');
set(h(2), 'XLim', new_xlim_for_top_axes, 'YLim', new_ylim_for_top_axes');
set(h(1), 'XLim', new_xlim_for_bottom_axes);
If you wanted to you could then
savefig(fig, 'editted_A_SubplotTest.fig');
  1 件のコメント
Brad
Brad 2018 年 1 月 26 日
Walter, I forgot all about the findobj function. Thanks for taking a look at this. It runs like a champ!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSubplots についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by