필터 지우기
필터 지우기

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

채택된 답변

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