Borrar filtros
Borrar filtros

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

19 visualizaciones (últimos 30 días)
kamaboko_tarou
kamaboko_tarou el 17 de Nov. de 2022
Comentada: kamaboko_tarou el 18 de Nov. de 2022
グラフの一部の拡大図を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']);

Respuesta aceptada

Hernia Baby
Hernia Baby el 17 de Nov. de 2022
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 comentarios
Hernia Baby
Hernia Baby el 17 de Nov. de 2022
そもそも元図はいらないんですね
それでしたら '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 el 18 de Nov. de 2022
何度もありがとうございます。
教えていただいた方法をもとに、プログラム作成に励みます。

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Community Treasure Hunt

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

Start Hunting!