Home > Enterprise >  Limit of Decreasing Plot Size in MATLAB
Limit of Decreasing Plot Size in MATLAB

Time:01-25

I use MATLAB R2021b. I have a 10x10 data array and I am using contourf function to plot the data. By default, MATLAB gives me a figure with 1120x840 pixels.

I know that I can use the command set(gcf, 'position', [700, 700, 100, 100]) to decrease the size of the figure. And I get a figure with 200x200 pixels. I decided to shrink the value in the set function by half to get a 100x100 figure.

However, when I try to do set(gcf, 'position', [700, 700, 50, 50]) , I got a figure with size 100x160. No matter how much further I decrease the value in the set function, the second dimension of the figure remained at 160 pixels. And there's no problem with the first dimension -- it can shrink with the value in the set function.

Does anyone know what's the problem here? My goal is to get a figure with 100x100 pixels.

Thank you very much for any advice!

CodePudding user response:

MATLAB has always had a minimal size for figure windows. A smaller window cannot contain the minimal set of menus and toolbar buttons.

But you don’t need a small window to export a small plot.

When exporting a plot, MATLAB uses the “PaperPosition” and “PaperUnits” figure properties. Set the units to pixels and the size to your required sizes to export the figure in those sizes.

There are of course other alternatives:

  • Set the axes to your required sizes, then export only the axes area (or crop the produced image to size).
  • Export a figure at twice (or four times) the size, then resample by a factor 1/2 (or 1/4).

If you’re not exporting, and just want a small display on the screen, consider putting multiple things in the same figure window, all you need to do is control the axes’s “Position” property.

CodePudding user response:

I am the original poster. I think there is a minimum window size in both Windows and Mac operating systems. 100 pixels are smaller than the minimum windows size, so I cannot generate such a small figure. This should be the answer for my question.

  • Related