Matplotlib duplicate axis or number?

I have several lines, bars and artists in one figure / axes. I would like to add various sets of components to the original shape / axis. Is it possible to duplicate all the objects of the original shape / axis to another shape / axis without redrawing the entire code?

One way is to remove all newly added components before drawing another set of components. However, if I want to put several axes in one shape, this will not work. Some discussion has been made here . But it copies / adds all objects one by one, which is no better than redrawing everything when there are many objects.

@Greg, thanks a lot for the answer. If I just print the data, it will be simple, just copy the data or even copy some lines. However, these numbers contain many artists, which can also be added by the user through the GUI or bot on the fly script, their types that I might not know at runtime. And the plot is generated "on the fly." Of course, I can try to copy all the data, write all types, properties and repeat them again. But this is too much and is due to the modification of the software that generates these numbers. Maybe I can cross all possible do copy and add_xxx . But I will bet there the best way.

Thanks to @Joe Kington and his post: "add an instance of axes to another drawing . "

I wrapped a way to duplicate axes and insert the axes in the subtitle:

 def test_pickleAxes(): import pickle import numpy as npy x = npy.arange(0,4*npy.pi,0.2) y = npy.sin(x) fig, ax = plt.subplots() p = pickle.dumps(ax) ax2 = pickle.loads(p) ax.change_geometry(2,1,1) ax2.change_geometry(2,1,2) fig._axstack.add(fig._make_key(ax2), ax2) plt.show() 

However, in most cases, it does not seem to be better than blit . Why is this? Because the axle pickle is actually the pickle of the whole figure. When it is printed, it will create a new shape, and an instance of the loaded axes will be associated with it. Even we managed to add axes to the old figure. ax2 is still ONLY associated with the new drawing. Thus, when we try to interact with the old figure, ax2 will not interact. Instead, if we scale / pan a new drawing, then ax2 will change in both figures. If we just save the svg or pdf file, it looks quite normal.

Try to find a way to separate ax2 from the new shape and connect it to the old one.

+5
source share

Source: https://habr.com/ru/post/1210343/


All Articles