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

enter image description here

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

enter image description here


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -