Change axes position in tiled layout
27 views (last 30 days)
Show older comments
Hello,
I am trying to minimize my spacing in a tiled layout. As some y axes have labels and some don't, the TileSpacing settings dont quite do the job. Therefore, I want to set each individual axes position.
This is possible with the property inspector by just dragging the axes, so I guess it should also be possible by code. However, when I try to do this, I get the warning: 'Warning: Unable to set 'Position', 'InnerPosition', 'OuterPosition', or 'PositionConstraint' for objects in a TiledChartLayout ' and it does not have any effect.
Here is an example code:
tiledlayout(2,1)
nexttile
plot(rand(5,1))
nexttile
plot(rand(5,1))
set(gca,'Position',[0.5,0.1,0.2,0.2])
I also tried to define the "nexttile" as an object and change its position, but it has the same result.
Does anyone have a solution for this?
Cheers,
Andreas
0 Comments
Accepted Answer
Matt J
on 24 Sep 2023
Edited: Matt J
on 24 Sep 2023
This File Exchange alternative gives considerable flexibility on the spacing,
Since it doesn't use tiledlayout, you can modify the comonent graph positions quite freely.
2 Comments
Adam Danz
on 24 Sep 2023
> I think it's wierd, that it works with the native tiledlayout with the property insepctor, but not with code.
The draggable axes borders in tiledlayout was a bug that was fixed in R2023b. Starting in R2023b, you can no longer manually resize the axes in a tiledlayout.
Prior to R2023b, when you manually resized the axes, it de-parented the axes from the TiledChartLayout. If a new axes were added via nexttile the entire TiledChartLayout object and all of its remaining axes would be deleted. Yikes!
Here's the buggy behavior prior to R2023b
figure()
tcl = tiledlayout(2,2);
ax1 = nexttile();
ax2 = nexttile();
now, manually resize ax2 by dragging an axes edge (<R2023b)
ax1.Parent % TiledChartLayout
ax2.Parent % Figure :(
now add a new axes
nexttile()
tcl % handle to deleted TiledChartLayout :(
ax1 % handle to deleted axes :(
More Answers (1)
Dyuman Joshi
on 24 Sep 2023
The position property for a tiledlayout refers to the position of the whole layout not each tile, see here - https://in.mathworks.com/help/matlab/ref/matlab.graphics.layout.tiledchartlayout-properties.html#mw_a2d6defe-bbec-469d-9571-f7d2c3d47968
You can use subplot in this case -
pos1 = [0.1 0.3 0.3 0.3];
subplot('Position',pos1)
y = magic(4);
plot(y)
title('First Subplot')
pos2 = [0.5 0.15 0.4 0.7];
subplot('Position',pos2)
bar(y)
title('Second Subplot')
0 Comments
See Also
Categories
Find more on Axes Appearance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
