MATLAB Answers

Ensure that patch is displayed

32 views (last 30 days)
Werner
Werner on 14 Aug 2013
I want to ensure that the patchs I plot are always displayed, not depending if they are to small compared to the current axes units.
The following minimal plot illustrates the issue:
axisLim=10000;
figure
hold on
plot(1:axisLim);
p1=patch([10 10 500 500],[0 axisLim axisLim 0],[1 1 1 1],
'EdgeColor','none',wFaceColor','r')
p2=patch([9000 9000 9001 9001],[0 axisLim axisLim 0],[1 1 1 1],
'FaceColor','r','EdgeColor','none')
The patch p1 will be visible, whereas the second won't. How can I make sure that all patchs are visible?

  0 Comments

Sign in to comment.

Accepted Answer

Werner
Werner on 14 Aug 2013
To obtain the desired effect (always show the patches in-dependably on how small they are, put the 'EdgeColor' the same color as the 'FaceColor'.
axisLim=10000;
figure
hold on
plot(1:axisLim);
p1=patch([10 10 500 500],[0 axisLim axisLim 0],[1 1 1 1],...
'EdgeColor','r','FaceColor','r')
p2=patch([9000 9000 9010 9010],[0 axisLim axisLim 0],[1 1 1 1],...
'FaceColor','r','EdgeColor','r')
hold off
I think this behavior should make sense with another pair value variable, such as ('appearIfThickerThan',Units), where units could be specified with percentage axes units or inches or so on. The 'FaceColor',and 'EdgeColor' should work the same way if I use 'EdgeColor','none' or 'EdgeColor' with the same color as the 'FaceColor'.

  0 Comments

Sign in to comment.

More Answers (1)

David Sanchez
David Sanchez on 14 Aug 2013
Your second patch is visible if you zoom in the plot. Since you are drawing a patch so thin ( from 9000 to 9001 ) the resolution of the screen is not enough to make it visible. On the other hand, if you zoom in your plot in that region, you'll see your second patch right there. I would recommend a wider patch of at least 10 units:
axisLim=10000;
figure
hold on
plot(1:axisLim);
p1=patch([10 10 500 500],[0 axisLim axisLim 0],[1 1 1 1],...
'EdgeColor','none','FaceColor','r')
p2=patch([9000 9000 9010 9010],[0 axisLim axisLim 0],[1 1 1 1],...
'FaceColor','b','EdgeColor','none')
hold off

  3 Comments

David Sanchez
David Sanchez on 14 Aug 2013
To zoom in, use the magnifying glass with a + sign on it, from your plot window.
Walter Roberson
Walter Roberson on 14 Aug 2013
You can also zoom by setting xlim and ylim after you plot. This is how the magnifier tool works internally, other than the tool doing some house-keeping to keep track of the previous zooms so that you can zoom out to what you had before.
Werner
Werner on 14 Aug 2013
Yes, this is what it makes you think, that the resolution is not enough to show the patch. But, that is not the behavior I want, I would expect it to show the lines independent on how small or thin they are.

Sign in to comment.

Sign in to answer this question.

Tags