Setting Subplot Axes with Alpha Hull

5 次查看(过去 30 天)
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

采纳的回答

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
编辑: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 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by