Created
July 4, 2018 19:32
-
-
Save Marva82/1fb232576304e7087b77376a6f5037a1 to your computer and use it in GitHub Desktop.
Histogram Plotting in Python - 2 Plots on same Matplotlib axes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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