MATLAB Answers

Setting Subplot Axes with Alpha Hull

5 ビュー (過去 30 日間)
Ricky
Ricky 2015 年 2 月 4 日
編集済み: Ricky 2015 年 2 月 4 日
I wish to create a window with 2 sub-plots. In each of these subplots will be a number of Alpha Hulls. For clarity of display I need to set the x and y axis of the subplots, usually to the same scale. However, when setting the axis the plot appears in a 'letterbox' style and does not rescale to fill the window. When using other shapes it does.
I have illustrated this with the code below which is simplified from the code I am using.
In the left subplot I create a shape, set the transparency and resize the axis, the subplot keeps the full window height.
In the right subplot I draw an Alpha Hull set the transparency and rescale the axis exactly the same way, but instead of showing the full height plot we get a 'letterbox' type diplay with the top and bottom of the plot cut off.
You can exchange the remmed lines of code to swap it from left to right.
What is different about the Alpha Plot that prevents the axis rescaling the same and how do I get around it?
Thanks in advance,
Rich
%%Set variable
xp=[0.25; 0.25; 0.75; 0.75];
yp=[0.25; 0.5; 0.5; 0.25];
scnsize = get(0,'ScreenSize');
%%create figure and position
fig = figure(3);
XLims=[0 20];
YLims=[-2 2];
PlotNorm=subplot(1,2,1);
cla
PlotAbnorm=subplot(1,2,2);
cla
pos3 = [0, 0, scnsize(3), scnsize(4)/2];
set(fig,'OuterPosition',pos3)
%%create Alpha Hull
HullRes=0.5;
HullPoints=[xp,yp];
AlphaHull=alphaShape(HullPoints,HullRes);
%%Plot
subplot(PlotNorm);
% AH=plot(AlphaHull,'FaceColor','r','LineStyle','none');
AH=fill(xp,yp,'r');
set(AH,'FaceAlpha',0.2);
set(gca,'XLim',XLims);
set(gca,'YLim',YLims);
hold on
subplot(PlotAbnorm);
AH=plot(AlphaHull,'FaceColor','r','LineStyle','none');
% AH=fill(xp+0.25,yp-0.25,'r');
set(AH,'FaceAlpha',0.2);
set(gca,'XLim',XLims);
set(gca,'YLim',YLims);
hold on

  0 件のコメント

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

採用された回答

Mike Garrity
Mike Garrity 2015 年 2 月 4 日
The plot method for alphaShape sets the DataAspectRatio of the axes. You can get the same effect for your other axes by either adding this:
axis equal
or this
set(gca,'DataAspectRatio',[1 1 1])
right before your call to subplot(PlotAbnorm).
The plot method of alphaShape does this because alpha shapes are often used for geometry which is in uniform coordinate systems, but fill is used for a much wider variety of purposes, so it doesn't do this.

  1 件のコメント

Ricky
Ricky 2015 年 2 月 4 日
Thank you! Pointed me in the right direction perfectly.
I actually want to prevent the behaviour the Alpha Hull was creating though so what I actually needed to do is add
set(gca,'DataAspectRatioMode','Auto');
After the "AH=plot(AlphaHull...." line to turn off the fixed aspect ratio.
Thanks again.

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

その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by