How to flip a patch graph/diagram?

6 views (last 30 days)
Hey,
I want to flip a triangle I plotted with patch. See the picture for clarification.
I don't want anything else (e.g. axes) to be changed. Is there an easy way to do this?

Accepted Answer

Walter Roberson
Walter Roberson on 16 Dec 2015
XL = get(gca, 'XLim');
patch_X = get(patch_handle, 'XData');
new_X = XL(2) - patch_X + XL(1);
set(patch_handle, 'XData', new_X);
You did not say which axis to flip it around, so I choose the middle of the displayed data rather than middle of the patch data or half of the patch data or around its right-most point.
  4 Comments
Sina
Sina on 18 Dec 2015
Okay.. Well, I have a lot of patches in my figure that I all want to be flipped so it doesn't work. I should have said that right up front. Sorry. I solved the problem though. I flipped the X-Axis and changed the labels.
set(gca,'XDir','reverse');
Label = get(gca,'XTickLabel');
set(gca,'XTickLabel', flipud(Labels));
Walter Roberson
Walter Roberson on 18 Dec 2015
Edited: Walter Roberson on 18 Dec 2015
You could iterate through all of the patch handles.
for patch_handle = findobj(gca, 'type', 'patch')
...
end
If they are not all in the same axes then a slight be more work needs to be done in order to get the correct XLIM for the axes they are in.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!