2015-04-29 5 views
5

pandas' documentation में आप क्षेत्र भूखंड पर चर्चा कर सकते हैं, और विशेष रूप से उन्हें ढेर कर सकते हैं। वहाँ एक आसान और सरल तरीके से इस एकएक पांडा का 100% क्षेत्र साजिश डेटाफ्रेम

enter image description here

this post से

की तरह एक 100% क्षेत्र ढेर भूखंड पाने के लिए है?

उत्तर

8

विधि मूल रूप से the other SO answer जैसा ही है; पंक्ति का योग करते हुए प्रत्येक पंक्ति को विभाजित:

df = df.divide(df.sum(axis=1), axis=0) 

तो फिर तुम df.plot(kind='area', stacked=True, ...) हमेशा की तरह कह सकते हैं।


import numpy as np 
import pandas as pd 
import matplotlib.pyplot as 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 to avoid "whitespace" 

plt.show() 

पैदावार

enter image description here

+1

एक और संभावना है 'pandas.DataFrame.plot.area है()' – Dror

संबंधित मुद्दे