グラフの一部の拡大図のみ保存したい

10 ビュー (過去 30 日間)
kamaboko_tarou
kamaboko_tarou 2022 年 11 月 17 日
コメント済み: kamaboko_tarou 2022 年 11 月 18 日
グラフの一部の拡大図をaxesのオプションで作成しました。拡大図のみを保存したいので、元のグラフを非表示にしたのですが、この状態で保存すると、拡大図の後ろに白い部分が存在してしまいます(添付画像)。作成した正方形の拡大図の部分のみを保存することは、可能でしょうか。
以下使用したコードです。
x = (1:2:9);
y = (1:2:9);
f = figure;
%ax1 = axes('Position',[0.1 0.1 0.7 0.7]);
ax2 = axes('Position',[0.2 0.2 0.4 0.4]);
%plot(ax1,x,y,'.r')
plot(ax2,x,y,'.r')
pbaspect([1 1 1])
%axis(ax1,[0 10 0 10])
axis(ax2,[0 4 0 4])
ax = gca;
ax.XTickLabel = [];
ay = gca;
ay.YTickLabel = [];
set(gca,'TickLength',[0 0])
rootname = 'image'; % 画像ファイル名
saveas(gca,['E:\image_edit\',rootname,'.png']);

採用された回答

Hernia Baby
Hernia Baby 2022 年 11 月 17 日
x = (1:2:9)';
y = (1:2:9)';
f = figure;
ax1 = axes('Position',[0.1 0.1 0.7 0.7]);
ax2 = axes('Position',[0.55 0.2 0.2 0.2]);
plot(ax1,x,y,'.r')
plot(ax2,x,y,'.r')
axis(ax1,[0 10 0 10])
axis(ax2,[0 4 0 4])
xlabel(ax1,'x');
ylabel(ax1,'y');
ここからが新しい回答です
新しい figure に ax2 をコピーしてサイズを変えています
fig2 = figure;
% 見えないようにするには'visible'を'off'にする
% fig2 = figure('visible','off');
f2 = copyobj(ax2,fig2);
set(f2, 'units', 'normalized', 'position', [0.1 0.1 0.8 0.8]);
後は f2 をsaveすればオッケーです
rootname = 'image'; % 画像ファイル名
saveas(f2,['E:\image_edit\',rootname,'.png']);
  2 件のコメント
Hernia Baby
Hernia Baby 2022 年 11 月 17 日
そもそも元図はいらないんですね
それでしたら 'Posision' の設定をなくしてください。
x = (1:2:9)';
y = (1:2:9)';
f = figure;
ax2 = axes;
plot(ax2,x,y,'.r')
axis(ax2,[0 4 0 4])
pbaspect([1 1 1])
axis off
kamaboko_tarou
kamaboko_tarou 2022 年 11 月 18 日
何度もありがとうございます。
教えていただいた方法をもとに、プログラム作成に励みます。

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchangeグラフィックス パフォーマンス についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!