tight window with axis('equal')
9 views (last 30 days)
Show older comments
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)]);
0 Comments
Answers (2)
Yair Altman
on 3 Mar 2016
Check whether the axes' undocumented LooseInset property can help you: http://undocumentedmatlab.com/blog/axes-looseinset-property
John BG
on 16 Feb 2016
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 Comments
Mike Garrity
on 22 Feb 2016
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')

See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!