필터 지우기
필터 지우기

Bounding box around image

조회 수: 15 (최근 30일)
Owen Gebler
Owen Gebler 2018년 10월 18일
댓글: Owen Gebler 2018년 10월 18일
I'm attempting to show an image within a plot, with a bounding box around the image. However, the following results in an image without a bounding box, despite the box being explicitly asked for:
clear
close all
% Create figure
fig1 = figure;
% Random plot
plot( (1:10), randi(10,1,10) )
% Create new axes within existing
axes('pos',[.1 .6 .5 .3])
% Load and show image
imshow('coins.png')
a1 = gca;
% Try turning box on and redrawing
a1.Box = 'on';
drawnow;
Any suggestions as to how this might be resolved? I'm hoping there's a simpler way than having to manually draw a box over the top...

채택된 답변

Image Analyst
Image Analyst 2018년 10월 18일
Try this:
% Random plot
plot( (1:10), randi(10,1,10), 'LineWidth', 2)
grid on; % Optional
% Create new axes on top of the existing plot.
axes('Position',[.1 .6 .5 .3])
% Load and show image
imshow('coins.png')
axis('on', 'image'); % This is the KEY LINE OF CODE!
Also see this link to learn how to format your code. http://www.mathworks.com/matlabcentral/answers/13205#answer_18099
  댓글 수: 1
Owen Gebler
Owen Gebler 2018년 10월 18일
That's exactly what I was after, thanks!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2018년 10월 18일
  댓글 수: 1
Owen Gebler
Owen Gebler 2018년 10월 18일
That's potentially a useful addition if more flexibility over the properties of the border is required. Thanks!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by