Clear Filters
Clear Filters

How to define the order of layers/plots and axes?

103 views (last 30 days)
I have some plots: p1 = plot(...); p2 = scatter(...). p3 = line(..); p4 = fill(...), p5 = imagesc(...); etc.
How to do the following?
1) Initialize these plots in arbitrary order, but not draw them yet!
2) Define the order of them, I mean: associate layers to them (top, bottom, etc.)
3) Draw them at the same time, with the above defined order (maybe set transparency also)
4) After plotting has been performed, is it possible to update a single layer and replot it, but with the appropriate untouched layers above it?
Note: And what if I have overlapping axes? Is it possible to associate layers to axes too?

Accepted Answer

Matt J
Matt J on 29 May 2023
Edited: Matt J on 29 May 2023
1) Hfig=figure('Visible','off); p(1) = plot(...); p(2) = scatter(...). p(3) = line(..); p(4) = fill(...), p(5) = imagesc(...)
2) Use the Children property of the plot axes set(gca,'Children', p([2,5,4,3,1[)
3) Hfig.Visible='on'. For transparency, you can set the FaceAlpha and MarkerFaceAlpha properties of those p(i) that have them. Line plots do not, however.
4) Use the XData and YData properties of p(i)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!