Multiple histograms in Pandas

As far as I can tell, pandas can’t handle this situation. That’s ok since all of their plotting methods are for convenience only. You’ll need to use matplotlib directly. Here’s how I do it:

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import pandas
#import seaborn
#seaborn.set(style="ticks")

np.random.seed(0)
df = pandas.DataFrame(np.random.normal(size=(37,2)), columns=['A', 'B'])
fig, ax = plt.subplots()

a_heights, a_bins = np.histogram(df['A'])
b_heights, b_bins = np.histogram(df['B'], bins=a_bins)

width = (a_bins[1] - a_bins[0])/3

ax.bar(a_bins[:-1], a_heights, width=width, facecolor="cornflowerblue")
ax.bar(b_bins[:-1]+width, b_heights, width=width, facecolor="seagreen")
#seaborn.despine(ax=ax, offset=10)

And that gives me:
enter image description here

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)