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

74 ビュー (過去 30 日間)
Vinicius Belarmino Almeida
Vinicius Belarmino Almeida 2021 年 8 月 22 日
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 件のコメント
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 8 月 22 日
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
Vinicius Belarmino Almeida 2021 年 8 月 22 日
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

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

採用された回答

Dave B
Dave B 2021 年 8 月 22 日
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 件のコメント
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 8 月 23 日
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
Vinicius Belarmino Almeida 2021 年 8 月 23 日
編集済み: Vinicius Belarmino Almeida 2021 年 8 月 23 日
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!

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

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by