Removing white space when using axis equal

30 ビュー (過去 30 日間)
AngDS
AngDS 2023 年 9 月 17 日
編集済み: Bruno Luong 2023 年 9 月 18 日
I am plotting a figure that needs to have an aspect ratio of 1:1. I am using axis equal and it is working to an extent. For some reason, my figure is in the middle of the image and there is a lot of white space around it. How do I fix this? I need the whole image to take up space. My current plotting code is below.
figure(1)
contourf(root_indices)
clim([1 5])
colormap parula
axis equal off
print(figure(2), '-djpeg', 'Roots Found at Seed Point Location1.jpg', '-r300')
  1 件のコメント
Walter Roberson
Walter Roberson 2023 年 9 月 17 日
Perhaps instead of using axis equal you might want to adjust the axes DataAspectRatio https://www.mathworks.com/help/matlab/ref/matlab.graphics.axis.axes-properties.html#budumk7-DataAspectRatio which can also be done using daspect
But see also PlotBoxAspectRatio axes property which can also be adjusted using pbaspect

サインインしてコメントする。

回答 (2 件)

Bruno Luong
Bruno Luong 2023 年 9 月 17 日
Call axis tight after axis equal
figure
imagesc(rand(10,50))
axis equal
axis tight
  2 件のコメント
AngDS
AngDS 2023 年 9 月 17 日
This didn't work. There is still so much white space around the image.
Bruno Luong
Bruno Luong 2023 年 9 月 18 日
編集済み: Bruno Luong 2023 年 9 月 18 日
After the plot use your mouse and resize the figure and eventually the axes with interactive tool (the arrow button in the toolbar)
You might use menu File => Generate Code and insert the relevant part in your code.

サインインしてコメントする。


DGM
DGM 2023 年 9 月 18 日
I'm going to guess that this is relevant:
Otherwise, if you fix both the figure and axes aspect ratios, then there must necessarily be a bunch of padding if they don't match.
In other words, the first step is to adjust the figure so that it's an appropriate shape.
Beyond that, you'll have to provide an example of what exactly your plots look like and what you expect them to look like, because it's not really all that clear why the data aspect ratio would uniquely create padding problems.

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by