2017-11-01 2 views
0
 max min mincount maxcount 
0  12 10  1  6 
1  21 14  1  6 
2  34 19  1  6 
3  6 20  1  4 
4  8 22  1  4 
5  41 23  1  4 

これはpandas DataFrameです。 だから私はこのイメージのようにしたい。python pandas bar plot別の列テキスト

enter image description here

テキストラベルは非常に重要です。ここ

私のコード

df = pd.DataFrame({'maxcount': max_count, 'mincount': min_count, 'max': max, 'min': min}) 
ax = df[['maxcount', 'mincount']].plot(kind='bar') 
+0

https://matplotlib.org/users/annotations_intro.html –

答えて

0
import pandas as pd 
import matplotlib.pyplot as plt 
%matplotlib inline 
import seaborn as sns 

#create your dataframe 
d= {'max':[12,21,34,6,8,41],'min':[10,14,19,20,22,23], 
'mincount':[1,1,1,1,1,1],'maxcount':[6,6,6,4,4,4]} 
df=pd.DataFrame(d) 
#create 2 dataframes counts and max_min (1 for plotting and 1 for text) 
counts=pd.DataFrame(df,columns=['maxcount','mincount']) 
max_min=pd.DataFrame(df,columns=['max','min']) 

#plot the counts 
ax=counts[counts.columns].plot(kind='bar',colormap='Paired',figsize= (12,4)) 

#using zip() and ax.annotate specify where (location by means of z) 
#and what (max_min or counts) you want to plot 
for x,y,z in zip(max_min.iloc[:,0].values,counts.iloc[:,0].values, range(len(counts))): 
    ax.annotate('%.d' % x, (z-0.2, counts.iloc[z,0]), va='bottom', ha='center', fontsize=10) 
    ax.annotate("("'%.d' % y+")", (z-0.1, counts.iloc[z,0]), va='bottom', ha='center', fontsize=10) 

for x,y,z in zip(max_min.iloc[:,1].values,counts.iloc[:,1].values, range(len(counts))): 
    ax.annotate('%.d' % x, (z+0.1, counts.iloc[z,1]), va='bottom', ha='center', fontsize=10) 
    ax.annotate("("'%.d' % y+")", (z+0.2, counts.iloc[z,1]), va='bottom', ha='center', fontsize=10) 

これが出力されます: enter image description here

+0

おかげgreateの!!!! – Nox10009

関連する問題