2016-08-07 2 views
1

バーとラインを1つのチャートにプロットする必要があります。私はバーをプロットすると、それが正しく表示される(G1およびG10が完了して表示される):enter image description herematplotlibプロットバーとラインチャートを一緒に

をしかし、私はプロットに行を追加する場合:

m1_t[['abnormal','fix','normal']].plot(kind='bar') 
m1_t['bad_rate'].plot(secondary_y=True) 

棒グラフは、(G1以下のように不完全であり、 g10は切り刻まれます): enter image description here

この問題を解決するにはどうすればよいですか?

+0

プロットのxlimitを調整するだけです – GWW

答えて

1

は、プロットの順番を切り替えてみてください:

ax = m1_t['bad_rate'].plot(secondary_y=True) 
m1_t[['abnormal','fix','normal']].plot(kind='bar', ax=ax) 

または元の棒グラフxlim保存:

ax = m1_t[['abnormal','fix','normal']].plot(kind='bar') 
m1_t['bad_rate'].plot(secondary_y=True, xlim=ax.get_xlim()) 
2

をあなたがXLIMとx軸を拡張する必要があります。

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

width = .35 # width of a bar 

m1_t = pd.DataFrame({ 
'abnormal' : [90,40,30,30,30,25,25,20,15,10], 
'fix' : [60,70,65,70,70,60,50,45,45,45], 
'normal' : [140,160,170,180,190,200,210,220,230,240], 
'bad_rate' : [210,100,100,70,70,75,70,60,65,60]}) 

m1_t[['abnormal','fix','normal']].plot(kind='bar', width = width) 
m1_t['bad_rate'].plot(secondary_y=True) 

ax = plt.gca() 
plt.xlim([-width, len(m1_t['normal'])-width]) 
ax.set_xticklabels(('G1', 'G2', 'G3', 'G4', 'G5', 'G6', 'G7', 'G8', 'G9', 'G10')) 

plt.show() 

enter image description here

今後の質問については、データフレームを投稿してください。

関連する問題