How to bring a plot to the front or back among multiple plots

754 ビュー (過去 30 日間)
Liqing
Liqing 2012 年 2 月 24 日
コメント済み: Yogishree Arabinda 2024 年 4 月 25 日 15:48
I have some interpolated ocean data that goes to land. I am thinking to first plot the interpolated values using 'scatter', and then plot the map using 'fill'. But the problem is that, it does not matter which one I plot first, the scatter plot is always on top. My question is how do I bring the scatter plot to back (behind the fill plot)?
Thank you,

採用された回答

Walter Roberson
Walter Roberson 2012 年 2 月 24 日
Are you using transparency? Or does
get(gca, 'Renderer')
return OpenGL ?
If so then note that OpenGL does not pay attention to the child order: it works in (projected) Z order. It also has rules about what happens if there is a line and a surface in the same plane: the order is determined by the graphic type. I never bothered to remember which order OpenGL defines in this case, as I have encountered graphics driver that get the order exactly backwards.
In the case of OpenGL, you need to make sure that the item that you want to be on "top" has a higher (projected) Z coordinate, closer to the front from the perspective of the viewer. That can involve using scatter3() instead of scatter() and specifying a constant Z coordinate above or below the implied Z=0 of other objects.
  4 件のコメント
Walter Roberson
Walter Roberson 2013 年 5 月 31 日
image() objects are 2D objects, not 3D objects whose Z happens to be 0. The difference between 2D and 3D with a constant Z can be seen when you tilt the perspective: when not seen from the top, the 2D object will vanish except for its edge, whereas the 3D object with constant Z will do the expected projection to become an angled surface.
pcolor is equivalent to surf() followed by view([0 90])
If you want to be able to tilt an image then you need to texture map it onto either a surface() object or a patch() object. Those steps are also required if you want to give an image a specific z coordinate so as to get layering as appropriate for your situation.
Walter Roberson
Walter Roberson 2021 年 7 月 15 日
編集済み: Walter Roberson 2021 年 7 月 15 日
Note: as of R2014b, the available options changed. See https://blogs.mathworks.com/graphics/2014/11/04/sortmethod/

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

その他の回答 (4 件)

the cyclist
the cyclist 2012 年 2 月 24 日
The "Children" property of the axis is a list of the handles of the objects on the plot. In general, the order of that list determines the layering.
Here is a simple example where I manipulate the order of that list:
[EDITED in response to comment.]
figure
scatter(rand(150,1),rand(150,1))
hold on
fill([0.2 0.5 0.5 0.2],[0.2 0.2 0.5 0.5],'r')
hg = line([0 0.6],[0.6 0]);
set(hg,'LineWidth',12,'Color','g')
h = get(gca,'Children');
set(gca,'Children',[h(3) h(2) h(1)])
  5 件のコメント
Parth Mishra
Parth Mishra 2021 年 6 月 18 日
This is great!! Thanks
Xiaohui Zhang
Xiaohui Zhang 2022 年 7 月 12 日
This works perfect! Thanks!

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


Aniruddh Murali
Aniruddh Murali 2017 年 12 月 7 日
I have an image and two points. Each point should have its trail shown and the image should be changed each time. How do I do that?
  2 件のコメント
the cyclist
the cyclist 2017 年 12 月 7 日
I suggest you open a new question for this, rather than appending an "answer" onto a four-year-old question that is barely related to what you want to do.
When you open your new question, please add significantly more detail about what you want. What you have written does not give sufficient information for us to help you.
Austin Coleman
Austin Coleman 2021 年 4 月 1 日
lol this guy was irritated. If you took the time to respond to a "4 year old question" just answer the question hahaha

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


Thelanorth
Thelanorth 2019 年 2 月 26 日
What worked for me, I wanted to draw some lines etc. over a data, was to just use plot3([x1 x2],[y1 y2],[z1 z2]) ipv plot([x1 x2],[y1 y2]).
This means that just adding a z coordinate higher than you data might work.

D
D 2023 年 2 月 12 日
編集済み: D 2023 年 2 月 12 日
A quick way to move the top child all the way to the bottom would be to use circshift:
hax = gca;
hax.Children = circshift(hax.Children, -1);
  2 件のコメント
Walter Roberson
Walter Roberson 2023 年 2 月 12 日
When you are dealing with 3D graphics, the child order can influence what is drawn, but there are other important factors as well; https://blogs.mathworks.com/graphics/2014/11/04/sortmethod/
Yogishree Arabinda
Yogishree Arabinda 2024 年 4 月 25 日 15:48
Thanks a lot it worked for me. Just needed to change from '-1' to '-2' as I had to bring the line below two other curves.

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

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by