How can I add a border around a figure window (not just the current axis)?

79 ビュー (過去 30 日間)
Vincent Bell
Vincent Bell 2020 年 12 月 2 日
回答済み: Image Analyst 2020 年 12 月 2 日
I want to add a border window around a figure window and not just the plot area. I want the box to include xlabel, ylabel, and title of the plot plus other text in the figure sides. Below is a copy of what I want boxed:
x = 0:pi/100:10*pi;
y = -1 + 2*cos(x);
f = figure;
f.WindowState = 'maximize';
f.Color = 'white';
plot(x,y);
f.CurrentAxes.Position=[0.1 0.1 0.85 0.85];
grid on;
xlabel('X','FontSize',16)
ylabel('Y','FontSize',16)
title('Trial','FontSize',20)
text([-3.5 31.5],[1.1 -3.3],'Graph of -1 + 2*cos(x)','Color','r','FontSize',18)
saveas(f,'PIC','png');

回答 (1 件)

Image Analyst
Image Analyst 2020 年 12 月 2 日
Try this:
x = 0:pi/100:10*pi;
y = -1 + 2*cos(x);
f = figure;
f.WindowState = 'maximize';
f.Color = 'white';
plot(x,y);
f.CurrentAxes.Position=[0.1 0.1 0.85 0.85];
grid on;
xlabel('X','FontSize',16)
ylabel('Y','FontSize',16)
title('Trial','FontSize',20)
text([-3.5 31.5],[1.1 -3.3],'Graph of -1 + 2*cos(x)','Color','r','FontSize',18)
% Shrink the axes.
ax = gca;
ax.Units = 'normalized';
ax.Position = [.1, .1, .8, .8];
% Add a red frame to the figure.
f.Units = 'normalized';
lineWidth = 50; % Whatever you want.
annotation('line', [0, 0], [0, 1], 'LineWidth', lineWidth, 'Color', 'r');
annotation('line', [1, 1], [0, 1], 'LineWidth', lineWidth, 'Color', 'r');
annotation('line', [0, 1], [0, 0], 'LineWidth', lineWidth, 'Color', 'r');
annotation('line', [1, 0], [1, 1], 'LineWidth', lineWidth, 'Color', 'r');
msgbox('Done!');

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by