I am trying to plot three histograms side-by-side (one row, 3 columns) by using a for loop and iterating over the same code but for a different column. I found two different methods, one is to use the plt.subplots(1, 3, i) and then iterate over i, and the other is to explicitly set fig, ax = plt.subplots() and replace each plt with ax[i] and iterate over that.
However neither of these works properly because of the additional lines I plot on the histogram(s).
How could I make this code work for side-by-side plots?
for parameter in ['k', 'm', 'sig']:
plt.hist(df[parameter], density=True, bins=20, label=parameter, ec='black')
mn, mx = plt.xlim()
plt.xlim(mn, mx)
kde_xs = np.linspace(mn, mx, 301)
kde = st.gaussian_kde(df[parameter])
plt.plot(kde_xs, kde.pdf(kde_xs), label="PDF")
plt.legend(loc="upper left")
plt.ylabel('Frequency')
plt.xlabel([parameter])
plt.title(f"Histogram for bootstrapped: {parameter}")
plt.axvline(df[parameter].mean(), color='r', linestyle='solid',
linewidth=2)
Axes.axvlinethen? - BigBenax.set_xlimandax.set_title? - BigBen