tight window with axis('equal')

조회 수: 13 (최근 30일)
Trevor
Trevor 2016년 2월 15일
댓글: Trevor 2016년 4월 15일
I have a plot which needs to have equal axes. I want to make the figure window tight around this plot so I can put it in a document. The code below attempts to do this, but fails because it leaves a margin on the left and right. Does anyone know of a way to do this?
figure;
xv = 0:.1:10;
yv = 0:.1:10;
F = rand(101,101);
imagesc(xv, yv, F);
set(gca,'XTickLabel',[]);
set(gca,'YTickLabel',[]);
axis('equal','xy');
axis([0 10 0 10]);
ti = get(gca,'TightInset');
set(gca,'Position',[ti(1) ti(2) 1-ti(3)-ti(1) 1-ti(4)-ti(2)]);

답변 (2개)

Yair Altman
Yair Altman 2016년 3월 3일
Check whether the axes' undocumented LooseInset property can help you: http://undocumentedmatlab.com/blog/axes-looseinset-property
  댓글 수: 1
Trevor
Trevor 2016년 4월 15일
Doesn't seem to help in this case, but thanks for the suggestion.

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


John BG
John BG 2016년 2월 16일
i grab the axis handle with
ax=gca
set(gca,'TightInset',[0 0 0 0]);
does not work because TightInset is read only.
try
ax.Position=[0 0 1 1]
this nulls above and below, yet there's still a bit of void on left and right that you may want to get rid of. If you open
propertyeditor('on')
PaperSize is [21 29.7] may be you want the paper set paper square shape.
In any case, write the following
xv = 0:.1:10
yv = 0:.1:10
F = rand(101,101)
imagesc(xv, yv, F)
axis([0 10 0 10])
ax=gca
ax.Position
ax.Position=[0 0 1 1]
when you save the image, not as .fig, but as .jpg, it seems quite tight to me.
If you find this answer of any help solving your question, please click on the above thumbs-up vote link, thanks in advance
John
  댓글 수: 9
Mike Garrity
Mike Garrity 2016년 2월 22일
You can use getframe to get the contents of the plot window, and then use imwrite to save that:
imshow('street1.jpg')
hold on
scatter(640*rand(1,150),480*rand(1,150),36,rand(1,150),'filled')
img = getframe(gcf)
imwrite(img.cdata,'myplot.png')
Trevor
Trevor 2016년 2월 22일
Thanks, I could use this as a work around. Do you know if it is possible to include ticks and other axis things using this technique?

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

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by