How do I increase the figure size without streching my plot?

79 views (last 30 days)
Hi,
I'm plotting a 3d mesh along with a colorbar on the side. Unfortunately the default figure size is cropping my colormap labels. I've tried changing my figure's position attribute, but then it changes my plot aspect ratio.
How do I increase the figure size without streching my plot?
Thanks,
Vinícius.
  4 Comments
Bjorn Gustavsson
Bjorn Gustavsson on 22 Aug 2021
Would it be possible for you to abreviate the tick-labels on the colorbar? That would save you valuable space. Can you rotate the ticklabels in your matlab-version?
Vinicius Belarmino Almeida
I can abreviate, but only to a certain extent, which doesn't solve the problem entirely and I'd rather not go this route.
I don't see a parameter for the tick labels angle :( But I don't think it would fit anyways

Sign in to comment.

Accepted Answer

Dave B
Dave B on 22 Aug 2021
A few different solutions (demos below):
  • If you don't want the changing figure position to change the aspect ratio, set the aspect ratio. There are two controls for this on the axes: PlotBoxAspectRatio and DataAspectRatio. The way they interact can be a little confusing so it's best to experiment to get the results you want. Details here: https://www.mathworks.com/help/matlab/creating_plots/manipulating-axes-aspect-ratio.html
  • Set the position of the axes instead of the figure, I think this is what you were after?
  • When an axes is in a TiledChartLayout, we do a little bit better at positioning the colorbar. So, strange as it sounds, a single axes in a layout may do better at making the appropriate space for the colorbar. We're trying to improve this with each release, but if you're working with 2021a as noted in the question it should be pretty good. However this will adjust the aspect ratio, so see above for how to constrain it.
% Original:
f=figure;
ax=axes;
surf(peaks);
colorbar('TickLabels','very long tick labels');
title('original');
% aspect ratio constrained, figure position adjusted
f=figure;
ax=axes;
surf(peaks);
colorbar('TickLabels','very long tick labels');
f.Position(3)=1000;
ax.PlotBoxAspectRatio=[1 1 1];
title('Figure position adjusted, not much better')
% Axes position adjusted to make space
f=figure;
ax=axes;
surf(peaks);
colorbar('TickLabels','very long tick labels');
ax.OuterPosition(3:4)=.75;
title('Axes Position Adjusted')
% TiledChartLayout approach
f=figure;
ax=nexttile;
surf(peaks);
colorbar('TickLabels','very long tick labels');
title('TiledChartLayout: may cramp your axes')
% TiledChartLayout with constrained aspect ratio
f=figure;
ax=nexttile;
surf(peaks);
ax.DataAspectRatio=[1 1 .5];
colorbar('TickLabels','very long tick labels');
title('TiledChartLayout + DataAspectRatio')
  2 Comments
Bjorn Gustavsson
Bjorn Gustavsson on 23 Aug 2021
For a step beyond the last figure I would still use something like numbers for the tick-marks and use them as footnote-marks and have the footnotes in the figure caption - all of those letters take up so much space of the figure where the data is shown. But this is obviously a design choise...
Vinicius Belarmino Almeida
Edited: Vinicius Belarmino Almeida on 23 Aug 2021
Unfortunately I can't use a footnote or even separate the legend from the plot. All the info must be next to the plot in this case...
The tiled chart layout seems to be the most straightfoward solution to me, as long as I set the aspect ratio.
Thanks!

Sign in to comment.

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!