Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在MATLAB图形窗口的边缘周围创建边框?_Matlab_Plot_Border_Matlab Figure - Fatal编程技术网

如何在MATLAB图形窗口的边缘周围创建边框?

如何在MATLAB图形窗口的边缘周围创建边框?,matlab,plot,border,matlab-figure,Matlab,Plot,Border,Matlab Figure,在将绘图保存到.png之前,我想在图形周围加一个边框,以便突出显示一些最重要的绘图。有没有办法在轴打印区域外绘制矩形 我希望边框能够围绕整个绘图延伸,甚至包括绘图标题和轴标签。您可以通过将轴放置在a中并调整、、和来创建各种边框类型。例如,这将创建一个宽青色边框,该边框具有从面板边缘延伸到地物边缘的倒角边: hFigure = figure('Color', 'c'); % Make a figure with a cyan background hPanel = uipanel(hFigure

在将绘图保存到.png之前,我想在图形周围加一个边框,以便突出显示一些最重要的绘图。有没有办法在轴打印区域外绘制矩形


我希望边框能够围绕整个绘图延伸,甚至包括绘图标题和轴标签。

您可以通过将轴放置在a中并调整、、和来创建各种边框类型。例如,这将创建一个宽青色边框,该边框具有从面板边缘延伸到地物边缘的倒角边:

hFigure = figure('Color', 'c');  % Make a figure with a cyan background
hPanel = uipanel(hFigure, 'Units', 'normalized', ...
                 'Position', [0.1 0.1 0.8 0.8], ...
                 'BorderType', 'BeveledIn');  % Make a panel with beveled-in borders
hAxes = axes(hPanel, 'Color', 'none');  % Set the axes background color to none
title('Title Here');


这将创建一个5像素宽的红线边框,紧挨着图形的边缘:

hFigure = figure();  % Make a figure
hPanel = uipanel(hFigure, 'Units', 'normalized', ...
                 'Position', [0 0 1 1], ...
                 'BorderType', 'line', ...
                 'BorderWidth', 5, ...
                 'BackgroundColor', 'w', ...
                 'HighlightColor', 'r');  % Make a white panel with red line borders
hAxes = axes(hPanel, 'Color', 'none');  % Set the axes background color to none
title('Title Here');

找到了解决方案。将打印保存到图像后,可以将其重新加载到地物中,然后在图像顶部绘制边框

img = imread('test_image.png');
fh = figure;
imshow(img,'border','tight')
hold on;
figurepos = get(gcf,'Position');
rectangle('Position',[4 4 figurepos(3)-7 figurepos(4)-7],'LineWidth',5,'EdgeColor','red')
两种选择:

1-将设置为“关闭”,并在轴边界外绘制一个矩形。您必须使用轴的单位来确定正确的位置。要在不同的图中保持一致,这可能有点困难

2-创建一个次轴,使其不可见,调整其大小以占据整个图形,并在其中绘制一个矩形:

f = figure
% One axes is invisible and contains a blue rectangle:
h = axes('parent',f,'position',[0,0,1,1],'visible','off')
set(h,'xlim',[0,1],'ylim',[0,1])
rectangle(h,'position',[0.01,0.01,0.98,0.98],'edgecolor',[0,0,0.5],'linewidth',3)
% Another axes is visible and you use as normal:
h = axes('parent',f)
plot(h,0:0.1:10,sin(0:0.1:10),'r-')

(我在这里明确地使用了
f
h
作为“父”对象,因为这通常会导致更健壮的代码,但您当然可以将它们排除在外,并依靠隐式使用的
gcf
gca
在大多数情况下做正确的事情。)

我希望边框延伸到整个绘图,包括标题和轴标签,因此我认为“box”命令不适用于这种情况