I have a plot that requires a lot of computation to generate (bar chart with many bins similar to the one below). I want to have that histogram plotted against other functions that are easy and fast to compute, so the figures would be function + histogram.
Figure 1 => Bar + function A
Figure 2 => Bar + function B
Is this possible to save the bar plot or data somehow and re-render it for different plots, without re-running plt.hist
?
import numpy as np
import matplotlib.pyplot as plt
import math
t = np.linspace(0, 2*math.pi, 400)
a = np.sin(t)
b = np.cos(t)
plt.hist(t,bins=1000,cumulative=False,bottom=True)
plt.plot(t, a, 'r') # plotting t, a separately
plt.show()
plt.plot(t,b,'r')
plt.hist(t,bins=1000,cumulative=False,bottom=True)
plt.show()