2017-02-21 222 views
0

我有如下一個數據幀:大熊貓/ matplotlib圖軸

        Rate per 100,000 population Gambling EXP per Adult 
Local Government Area              
City of Banyule        7587.7    555.188876 
City of Bayside        5189.9    171.282451 
City of Boroondara       4877.0    141.675636 
City of Brimbank       9739.0    904.959407 
City of Casey        7790.6    561.086313 

我在與對應於右邊兩列與最左列是所述兩個y軸繪製多次嘗試x軸上。但到目前爲止,我只設法爲兩者獲得一個軸。我試圖模仿這裏的解決方案:http://matplotlib.org/examples/api/two_scales.html但我一直在失敗。我也看過其他的計算器Q & S,但到目前爲止還沒有發現它們非常清楚。如果有人能幫我解決這個問題,那將會很棒。乾杯。

回答

1

你真的應該包括你試過的代碼,以便人們可以真正指出你正確的方向。儘管如此,我猜你已經錯過了pandas會打開一個新的圖形和新的軸對象,除非你指定一個預先存在的軸來繪製。

import pandas as pd 
import matplotlib.pyplot as plt 

# separate data file 
dat = pd.read_csv('dat.csv', index_col='Local Government Area') 

fig = plt.figure() 
ax1 = fig.add_subplot(111) 
ax2 = ax1.twinx() 

# the ax keyword sets the axis that the data frame plots to 
dat.plot(ax=ax1, y='Rate per 100 000 population', legend=False) 
dat.plot(ax=ax2, y='Gambling EXP per Adult', legend=False, color='g') 
ax1.set_ylabel('Rate per 100,000 population') 
ax2.set_ylabel('Gambling EXP per Adult') 
plt.show() 

你需要更多地去獲得一個好看的情節,但是這應該讓你開始。