Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save Marva82/1fb232576304e7087b77376a6f5037a1 to your computer and use it in GitHub Desktop.

Select an option

Save Marva82/1fb232576304e7087b77376a6f5037a1 to your computer and use it in GitHub Desktop.
Histogram Plotting in Python - 2 Plots on same Matplotlib axes
#Plotting Kernel Density Estimate - Estimate of Probability Density Function
#Means of smoothing data
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
means = 15, 35
stdevs = 6, 12
distro = pd.DataFrame(np.random.normal(loc=means, scale=stdevs, size=(2000,2)),
columns=['1st', '2nd'])
distTable = (distro.agg(['min', 'max', 'mean', 'std']).round(decimals=3))
print(distTable)
#Plot each of the histograms on same Matplotlib axes
figure, ax = plt.subplots()
distro.plot.kde(ax = ax, legend=False, title='Histogram: 1st vs. 2nd')
distro.plot.hist(density=True, ax = ax)
ax.set_ylabel('Probability')
ax.grid(axis='y')
ax.set_facecolor('#C6E2FF')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment