How to bring a plot to the front or back among multiple plots
Show older comments
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,
Accepted Answer
More Answers (4)
the cyclist
on 24 Feb 2012
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 Comments
Liqing
on 24 Feb 2012
the cyclist
on 24 Feb 2012
I edited my answer to provide an example with three objects.
Junho Kweon
on 28 Mar 2019
I like this way. So simple and compatible for many cases. Thanks!
Parth Mishra
on 18 Jun 2021
This is great!! Thanks
Xiaohui Zhang
on 12 Jul 2022
This works perfect! Thanks!
Aniruddh Murali
on 7 Dec 2017
0 votes
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 Comments
the cyclist
on 7 Dec 2017
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
on 1 Apr 2021
lol this guy was irritated. If you took the time to respond to a "4 year old question" just answer the question hahaha
Thelanorth
on 26 Feb 2019
0 votes
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.
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 Comments
Walter Roberson
on 12 Feb 2023
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
on 25 Apr 2024
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.
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!