フィルターのクリア

how to crop figures from excess white area

68 ビュー (過去 30 日間)
Sven Larsen
Sven Larsen 2023 年 11 月 10 日
コメント済み: Sven Larsen 2023 年 11 月 14 日
i have a wind rose figure (see attachment) and I'm trying to get rid of white space around image. Preferably to control how there is white space around given image. If I try to fiddle with figure property inspector, it just resizes image and wont reduce excess space.
basically, I want able to crop image like this:

採用された回答

Devon
Devon 2023 年 11 月 10 日
編集済み: Devon 2023 年 11 月 10 日
There are a couple of settings in the properties of the fig that deal with this. Overview of the properties are: https://www.mathworks.com/help/matlab/ref/matlab.ui.figure-properties.html
I was able to use the MATLAB command line to change the padding around the image.
figure = openfig("example.fig")
This will save all of the properties of example.fig to figure. You can then look at some position values to get location and size of the image area specified as a vector of the form [left bottom width height].
A couple of theses are Position, OuterPosition, InnerPostion. I am using Position for this example. I want to first get the current info:
figure.Position
ans =
600 600 230 280
I then want to set the width and height:
figure.Position = [600 600 200 200]
This preserves the plot dimensions and sets the padding to 200 pixes on each side. You can see the before and after:
This will still be not quite suare since the width and height values do not take into account the title space, but the borders are reduced.
  3 件のコメント
Devon
Devon 2023 年 11 月 13 日
編集済み: Devon 2023 年 11 月 13 日
You would need to save as a jpg or similar image format first.
The figure window itself cannot be cropped. It is a tool for dynamic viewing and modifications of plots. You can zoom in on a region of the plot, but not crop beyond that.
Sven Larsen
Sven Larsen 2023 年 11 月 14 日
Thank you for this information, it was very helpful! No I know cropping the figure via properties is not possible (the way I wanted), so I will write cropping code with imcrop.

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

その他の回答 (1 件)

William Rose
William Rose 2023 年 11 月 10 日
@Sven Larsen, One can reduce the whitespace by clicking and dragging the edgesof the image window so that it more closely matches the aspect ratio of the contents. With this approach I was able to get the attached result, saving the image as a .fig file. It is still not as tight as you would like. To reduce the whitespace more, I would save it in a different format, such as bmp, then use an external editor to crop as desired. See attached.
  3 件のコメント
Dyuman Joshi
Dyuman Joshi 2023 年 11 月 12 日
@Sven Larsen, Could you share the code that produces this figure?
Sven Larsen
Sven Larsen 2023 年 11 月 12 日
https://www.mathworks.com/matlabcentral/fileexchange/47248-wind-rose

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

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by