필터 지우기
필터 지우기

Wrong 'patch' area when plotting

조회 수: 2 (최근 30일)
10B
10B 2016년 5월 30일
댓글: Star Strider 2016년 5월 30일
Hello Community,
I am using the 'patch' function to plot 4 areas to aid with the grouping of some data when it is plotted. I have tried to make the code so that it will work with any size of plot, hence defining the x-limits (x_lim). The problem is, with the code I have written, the patches dont align as I would like:
% Define limits of axis
x_lim = get(gca,'xlim');
y_lim = get(gca,'ylim');
% Colour in the patches
patch([0 0 (x_lim(1,2)/4) (x_lim(1,2)/4)],[y_lim(1) y_lim(2) y_lim(2) y_lim(1) ],[1 0.5 0.2],'FaceAlpha',0.2)
patch([(x_lim(1,2)/4) (x_lim(1,2)/4) ((x_lim(1,2)/4)*2) ((x_lim(1,2)/4)*2) ],[y_lim(1) y_lim(2) y_lim(2) y_lim(1) ],[1 1 0.2],'FaceAlpha',0.2)
patch([((x_lim(1,2)/4)*2) ((x_lim(1,2)/4)*2) ((x_lim(1,2)/4)*3) ((x_lim(1,2)/4)*3)],[y_lim(1) y_lim(2) y_lim(2) y_lim(1) ],[0.5 1 0.7],'FaceAlpha',0.2)
patch([((x_lim(1,2)/4)*3) ((x_lim(1,2)/4)*3) x_lim(2) x_lim(2)],[y_lim(1) y_lim(2) y_lim(2) y_lim(1) ],[0.4 0.3 0.8],'FaceAlpha',0.2)
and they produce this plot:
What I would like to happen is that the patch groups around the first 4 box plots (group A), then the next patch covers the next 4 boxplots (group B) and so on.
I have tried various combinations of my code but haven't managed to get this to work in the way that I want. Can anyone offer a bit of help to resolve this please?
Kind regards,
10B.
  댓글 수: 1
10B
10B 2016년 5월 30일
Another combination - again not quite right.
patch([0 0 (x_lim(1,2)/3) (x_lim(1,2)/3)],[y_lim(1) y_lim(2) y_lim(2) y_lim(1) ],[1 0.5 0.2],'FaceAlpha',0.2)
patch([(x_lim(1,2)/3) (x_lim(1,2)/3) ((x_lim(1,2)/2)) ((x_lim(1,2)/2)) ],[y_lim(1) y_lim(2) y_lim(2) y_lim(1) ],[1 1 0.2],'FaceAlpha',0.2)
patch([((x_lim(1,2)/2)) ((x_lim(1,2)/2)) ((x_lim(1,2)/3)*2) ((x_lim(1,2)/3)*2)],[y_lim(1) y_lim(2) y_lim(2) y_lim(1) ],[0.5 1 0.7],'FaceAlpha',0.2)
patch([((x_lim(1,2)/3)*2) ((x_lim(1,2)/3)*2) x_lim(2) x_lim(2)],[y_lim(1) y_lim(2) y_lim(2) y_lim(1) ],[0.4 0.3 0.8],'FaceAlpha',0.2)

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2016년 5월 30일
You will have to define the patch x-values to correspond to the x-values of your data instead of segments of the x-axis. Define them for instance as the mean value of the 4th and 5th, 8th and 9th, and so for the rest.
  댓글 수: 2
10B
10B 2016년 5월 30일
Yet again, Star Strider to the rescue...
Thank you very much for your insight!
Star Strider
Star Strider 2016년 5월 30일
As always, my pleasure!
I wish you all the best in your research!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Polygons에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by