9951 explained code solutions for 126 technologies


python-pandasHow to draw overlay data frame bar charts


import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

a = {'a': np.random.normal(0,1,100), 'b' : np.random.normal(1,2,100)}
df = pd.DataFrame.from_dict(a)

df.plot.hist(alpha=0.5)
plt.show()ctrl + c
import pandas as pd

load Pandas module

import numpy as np

load Numpy module for Python

.random.normal(0,1,100)

generates 100 elements with 0 mean and 1 standard deviation

.DataFrame.from_dict

creates Pandas DataFrame object from given dict (a)

.plot.hist

plots DataFrame overlay bars chart

import matplotlib.pyplot as plt

loads Matplotlib module to use plotting capabilities

plt.show()

renders plotted data

alpha=0.5

make bars semi-transparent