필터 지우기
필터 지우기

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

조회 수: 19 (최근 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개)

제품

Community Treasure Hunt

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

Start Hunting!