python - 100% area plot of a pandas DataFrame -
in pandas' documentation can find discussion on area plots, , in particular stacking them. there easy , straightforward way 100% area stack plot one
from this post?
the method same in the other answer; divide each row sum of row:
df = df.divide(df.sum(axis=1), axis=0)
then can call df.plot(kind='area', stacked=true, ...)
usual.
import numpy np import pandas pd import matplotlib.pyplot plt np.random.seed(2015) y = np.random.randint(5, 50, (10,3)) x = np.arange(10) df = pd.dataframe(y, index=x) df = df.divide(df.sum(axis=1), axis=0) ax = df.plot(kind='area', stacked=true, title='100 % stacked area chart') ax.set_ylabel('percent (%)') ax.margins(0, 0) # set margins avoid "whitespace" plt.show()
yields
Comments
Post a Comment