イントロ
私はPython、matplotlib、pandasを初めて使っています。私は次のことを考え出すために多くの時間を費やしました。そして私は立ち往生している。パンダのデータフレーム描画:yscaleログとxyラベルと伝説の問題
質問:
私はパンダを使用してプロットしようとしています。私は3つのY軸を持ち、そのうちの1つは対数スケールです。 私のセカンダリ軸ax2のコードで、ログ機能()とラベル機能()が機能しない理由を理解できません。他のすべての場所で動作します。
すべての凡例が分離されています()。これを手動で行うよりも簡単な方法がありますか?
セカンダリ軸の部分をプロットすると、別に問題なく出力されます。私は3番目の軸を削除するプロットを実行し、まだ問題が続く。この方法で一緒に働くことが提案されたソリューションが必要なときに、私はここにすべての軸を含むコードを入れました。
Here()のみを解決する方法がありますが、特にデータフレームベースのプロットを探しています。同じサイトには他にも手作業のテクニックがありますが、私は使いたくありません!
コードと説明
# Importing the basic libraries
import matplotlib.pyplot as plt
from pandas import DataFrame
# test3 = Dataframe with 5 columns
test3 = df.ix[:,['tau','E_tilde','Max_error_red','time_snnls','z_t_gandb']]
# Setting up plot with 3 'y' axis
fig, ax = plt.subplots()
ax2, ax3 = ax.twinx(), ax.twinx()
rspine = ax3.spines['right']
rspine.set_position(('axes', 1.25))
ax3.set_frame_on(True)
ax3.patch.set_visible(False)
fig.subplots_adjust(right=0.75)
# Setting the color and labels
ax.set_xlabel('tau(nounit)')
ax.set_ylabel('Time(s)', color = 'b')
ax2.set_ylabel('Max_error_red', color = 'r')
ax3.set_ylabel('E_tilde', color = 'g')
# Setting the logscaling
ax.set_xscale('log') # Works
ax2.set_yscale('log')# Doesnt work
# Plotting the dataframe
test3.plot(x = 'tau', y = 'time_snnls', ax=ax, style='b-')
test3.plot(x = 'tau', y = 'Max_error_red', ax=ax2, style='r-', secondary_y=True)
test3.plot(x = 'tau', y = 'z_t_gandb', ax=ax, style='b-.')
test3.plot(x = 'tau', y = 'E_tilde', ax=ax3, style='g-')
うわーは、yourquickと作業応答、は、xlabelはまだ変更されません。ただ、もう一つのことをお願いいたします。それは 'タウ(nounit)'とは対照的に 'タウ'です。あなたは何が起こっているのか知っていますか?私たちは再び集める必要がありますか?そのために使用される方法は何ですか?ありがとうございました。 –
'ax.set_xlabel'行を' test3.plot'行の後ろに移動してみてください – tom
@ThejKiran: 'set_ {x、y} label'行を' plot'行の後ろに動かすことが確かですこの問題を修正してください。私の編集を見る – tom