Matplotlib duplicate digit and apply changes

I am making a series of numbers with the same layout. Since the layout accepts a lot of lines of code, I try to duplicate the first time, done and changing only a few things, such as markers, and, if possible, data, although I know that this can complicate the situation, as this will probably require rescaling so at the end, the "plt.show ()" command displays the original digit plus the duplicate.

0
source share
1 answer

I’m not sure that “duplicating the settings” in the form in which you are describing is really feasible ... it probably requires a lot of low-level access for all the objects involved in the layout (axes, axis objects, line objects, patch objects and etc.). I could be completely wrong, but this is my instinct. I put something here that may come close to what you want, although you don’t need to duplicate a lot of layout specifications.

import matplotlib.pyplot as plt import numpy as np def make_layout(data): fig = plt.figure() ax = fig.add_subplot(111) p, = ax.plot(data,'o') p.set_markerfacecolor('green') # Presumably lots of complicated settings here return fig, ax, p data = np.linspace(0,1) f1, a1, p1 = make_layout(data) f2, a2, p2 = make_layout(data**2) # Make the tweaks you want a2.set(axis_bgcolor='m') p2.set_markerfacecolor('yellow') 
+2
source

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


All Articles