169

を使用して左側の y 軸に y ラベルをplt.ylabel追加できますが、セカンダリ y 軸に追加するにはどうすればよいですか?

table = sql.read_frame(query,connection)

table[0].plot(color=colors[0],ylim=(0,100))
table[1].plot(secondary_y=True,color=colors[1])
plt.ylabel('$')
4

5 に答える 5

340

最善の方法は、axesオブジェクトを直接操作することです

import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 10, 0.1)
y1 = 0.05 * x**2
y2 = -1 *y1

fig, ax1 = plt.subplots()

ax2 = ax1.twinx()
ax1.plot(x, y1, 'g-')
ax2.plot(x, y2, 'b-')

ax1.set_xlabel('X data')
ax1.set_ylabel('Y1 data', color='g')
ax2.set_ylabel('Y2 data', color='b')

plt.show()

グラフの例

于 2013-02-07T22:52:14.123 に答える
11

現在Pythonにアクセスできませんが、頭から離れています。

fig = plt.figure()

axes1 = fig.add_subplot(111)
# set props for left y-axis here

axes2 = axes1.twinx()   # mirror them
axes2.set_ylabel(...)
于 2013-02-07T23:01:59.250 に答える