2012-07-24 4 views
35

を軸プロット大きなデータセットでは遅いです。PANDASは、私はパンダが二Y軸をサポートしていますが、Imは好奇心、誰もが...プロットに三次Y軸を配置する方法を知っていれば、現在私はnumpyの+ pyplotでこれを実現しています...しかし、それを知っている、複数のYは

これは、簡単に比較(例えば相対湿度/温度/及び電気伝導度)のために、同じグラフ上に個別の単位で異なる測定をプロットすることである

、これはあまりにもなしpandasに可能であれば誰もが知っているので、もし本当にただの好奇心仕事いっぱい。

[編集]私は

答えて

55

...これはmatplotlibのを制限することができ、しかし、私は間違って証明されることを望む(あまりにも多くのオーバーヘッドなしで)これを行う方法があることを疑う私はこれが働くかもしれないと思います:

import matplotlib.pyplot as plt 
import numpy as np 
from pandas import DataFrame 
df = DataFrame(np.random.randn(5, 3), columns=['A', 'B', 'C']) 

fig, ax = plt.subplots() 
ax3 = ax.twinx() 
rspine = ax3.spines['right'] 
rspine.set_position(('axes', 1.15)) 
ax3.set_frame_on(True) 
ax3.patch.set_visible(False) 
fig.subplots_adjust(right=0.7) 

df.A.plot(ax=ax, style='b-') 
# same ax as above since it's automatically added on the right 
df.B.plot(ax=ax, style='r-', secondary_y=True) 
df.C.plot(ax=ax3, style='g-') 

# add legend --> take advantage of pandas providing us access 
# to the line associated with the right part of the axis 
ax3.legend([ax.get_lines()[0], ax.right_ax.get_lines()[0], ax3.get_lines()[0]],\ 
      ['A','B','C'], bbox_to_anchor=(1.5, 0.5)) 

出力:

Output

+0

これは素晴らしいです。 ax2が必要ですか? – goofd

+0

このアプローチを使用すると、重複していた伝説に問題がありました。これは私に役立ちました: 'ax3.legend([ax.get_lines()[0]、ax2.get_lines()[0]、ax3.get_lines()[0]]、[label1 '、' label2 '、' label3 '] 、bbox_to_anchor =(1.15、0.5)) ' – tworec

+0

こんにちは!各軸に 'ylabel'をどのように追加するのだろうか?ありがとう! –

関連する問題