I am plotting multiple histograms in Matplotlib in one figure. This is working well when displaying it by using show(). When saving the figure using savefig(), only one or sometimes no graph is shown. Also, the quality of the figure is not as good as the one produced by show().
This is my code:
def plot_delta_ts_in_histo2(key1, values1, key2, values2):
fig = plt.figure()
plt.hist(values1, bins=[x for x in np.arange(0, 600, 1)], density=True, alpha=0.25, label=key1)
plt.hist(values2, bins=[x for x in np.arange(0, 600, 1)], density=True, alpha=0.25, label=key2)
plt.xlabel('Time in seconds')
plt.ylabel('Number of elements')
plt.legend(loc='upper right')
fig.savefig("./Plots/" + key1 + "_" + key2 + '.png', dpi=fig.dpi)
plt.show()
fig.clf()
The "key"-parameters are strings, while the "values"-parameters are a list of floats.
How can I fix this problem and how can i improve the quality of the plots?
Thanks in advance!