How to flip a patch graph/diagram?

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?

 採用された回答

Walter Roberson
Walter Roberson 2015 年 12 月 16 日

0 投票

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 件のコメント

Sina
Sina 2015 年 12 月 17 日
編集済み: Sina 2015 年 12 月 17 日
Hey, thank you for the fast reply. If I try this I get an "Undefined function or variable 'patch_handle'." If I put it in '' then I get an "Invalid handle"... What did I do wrong or is it a Matlab version problem? I am using Matlab R2015b... I hope you can help. Thank you. To flip the middle of the displayed data should be just perfect.
Walter Roberson
Walter Roberson 2015 年 12 月 18 日
patch_handle should be replaced by the handle of the patch you are attempting to flip.
For example,
patch_handle = fill(1:10,sin(1:10),'r');
and then the above code.
Sina
Sina 2015 年 12 月 18 日
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 2015 年 12 月 18 日
編集済み: Walter Roberson 2015 年 12 月 18 日
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.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

タグ

質問済み:

2015 年 12 月 15 日

編集済み:

2015 年 12 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by