, . , .
import numpy as np
import matplotlib.pyplot as plt
def myplot1(data, ax=None, show=False):
if not ax:
_, ax = plt.subplots()
ax.plot(data[0], data[1])
if show:
plt.show()
def myplot2(data, ax=None, show=False):
if not ax:
_, ax = plt.subplots()
ax.hist(data, bins=20, density=True)
if show:
plt.show()
x = np.linspace(-3, 3, 100)
y = np.exp(-x**2/2)/np.sqrt(2*np.pi)
a = np.random.normal(size=10000)
myplot1((x,y))
myplot2(a)
fig, ax = plt.subplots()
myplot1((x,y), ax=ax)
myplot2(a, ax=ax)
plt.show()
, , , :
import matplotlib.pyplot as plt
import numpy as np
import pickle
x = np.linspace(-3, 3, 100)
y = np.exp(-x**2/2)/np.sqrt(2*np.pi)
a = np.random.normal(size=10000)
fig, ax = plt.subplots()
ax.plot(x, y)
pickle.dump(fig, open("figA.pickle","wb"))
fig, ax = plt.subplots()
ax.hist(a, bins=20, density=True, ec="k")
pickle.dump(fig, open("figB.pickle","wb"))
plt.close("all")
figA = pickle.load(open("figA.pickle","rb"))
figB = pickle.load(open("figB.pickle","rb"))
fig, ax = plt.subplots()
for figO in [figA,figB]:
lists = [figO.axes[0].lines, figO.axes[0].patches]
addfunc = [ax.add_line, ax.add_patch]
for lis, func in zip(lists,addfunc):
for artist in lis[:]:
artist.remove()
artist.axes=ax
artist.set_transform(ax.transData)
artist.figure=fig
func(artist)
ax.relim()
ax.autoscale_view()
plt.close(figA)
plt.close(figB)
plt.show()
, . , , .
, , , , , .