Figure のサイズを変更するにはどうしたらよいですか?

302 ビュー (過去 30 日間)
MathWorks Support Team
MathWorks Support Team 2024 年 11 月 13 日
回答済み: MathWorks Support Team 2024 年 11 月 13 日

Figure のサイズを変更しようとしています。以下の例では、figure(2)のサイズを変更することを期待していました。そのために次のコードを追加しましたが、うまくいきません。なぜでしょうか?

set(gcf, 'PaperUnits', 'inches');
set(gcf, 'PaperSize', [4 2]);
set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperPosition', [0 0 4 2]);

clc;
clear all;
t = 0:.1:4*pi;
y = sin(t);
figure(1)
set(gcf, 'renderer', 'painters');
plot(t,y)
xlabel('Time(s)')
ylabel('y(t)')
title('Sin function')
legend('y=sin(t)')
axis([0 t(end) -1.5 1.5])
set(gca, 'Units', 'normalized', 'YTick', -1.5:.5:1.5, 'XTick', 0:t(end)/4:t(end), 'FontUnits', 'points', 'FontWeight', 'normal', 'FontSize', 9, 'FontName', 'Times')
set(gca, 'Position', get(gca, 'OuterPosition') - get(gca, 'TightInset') * [-1 0 1 0; 0 -1 0 1; 0 0 1 0; 0 0 0 1]);
figure(2)
set(gcf, 'renderer', 'painters');
set(gcf, 'PaperUnits', 'inches');
set(gcf, 'PaperSize', [4 2]);
set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperPosition', [0 0 4 2]);
plot(t,y)
xlabel('Time(s)')
ylabel('y(t)')
title('Sin function')
legend('y=sin(t)')
axis([0 t(end) -1.5 1.5])
set(gca, 'Units', 'normalized', 'YTick', -1.5:.5:1.5, 'XTick', 0:t(end)/4:t(end), 'FontUnits', 'points', 'FontWeight', 'normal', 'FontSize', 9, 'FontName', 'Times')
set(gca, 'Position', get(gca, 'OuterPosition') - get(gca, 'TightInset') * [-1 0 1 0; 0 -1 0 1; 0 0 1 0; 0 0 0 1]);

採用された回答

MathWorks Support Team
MathWorks Support Team 2024 年 11 月 13 日
ペーパーサイズのオプションは印刷用であり、図のサイズを変更するものではありません。
図のサイズを変更するには、Positionプロパティを使用します(デフォルトではピクセル単位)。このプロパティは [x y width height] の形式のベクトルで指定し、x と y は画面の左下隅から図の左下隅までの距離を定義します。また、set(gcf, ...) を複数回呼び出さずに、複数のプロパティを一度に設定することもできます。図を作成するときに含めることも可能です。
figure('Renderer', 'painters', 'Position', [10 10 900 600])
また、図のハンドルを保存し、ドット表記を使用してPositionプロパティを設定することもできます。
f = figure; f.Position = [100 100 540 400];
図のサイズをプログラムで変更する例については、以下のリンクを参照してください: MATLABのfigure関数の例
図のプロパティに関する詳細は、以下のドキュメントを参照してください: MATLAB UI Figure Properties

その他の回答 (0 件)

カテゴリ

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

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!