tight window with axis('equal')

13 visualizzazioni (ultimi 30 giorni)
Trevor
Trevor il 15 Feb 2016
Commentato: Trevor il 15 Apr 2016
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)]);

Risposte (2)

Yair Altman
Yair Altman il 3 Mar 2016
Check whether the axes' undocumented LooseInset property can help you: http://undocumentedmatlab.com/blog/axes-looseinset-property
  1 Commento
Trevor
Trevor il 15 Apr 2016
Doesn't seem to help in this case, but thanks for the suggestion.

Accedi per commentare.


John BG
John BG il 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 Commenti
Mike Garrity
Mike Garrity il 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')
Trevor
Trevor il 22 Feb 2016
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?

Accedi per commentare.

Categorie

Scopri di più su Environment and Settings in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by