帶有twinx()的輔助軸:如何添加到圖例?我有一個帶有兩個y軸的情節(jié),使用twinx()。我也給線條貼了標(biāo)簽,并希望用它們來展示legend(),但我只是成功地在圖例中獲得了一個軸的標(biāo)簽:import numpy as npimport matplotlib.pyplot as pltfrom matplotlib import rc
rc('mathtext', default='regular')fig = plt.figure()ax = fig.add_subplot(111)ax.plot(time, Swdown, '-', label = 'Swdown')ax.plot(time, Rn, '-', label = 'Rn')ax2 = ax.twinx()ax2.plot(time, temp, '-r', label = 'temp')ax.legend(loc=0)ax.grid()ax.set_xlabel("Time (h)")ax.set_ylabel(r"Radiation ($MJ\,m^{-2}\,d^{-1}$)")ax2.set_ylabel(r"Temperature ($^\circ$C)")ax2.set_ylim(0, 35)ax.set_ylim(-20,100)plt.show()所以我只得到圖例中第一個軸的標(biāo)簽,而不是第二個軸的標(biāo)簽“temp”。我怎么能將這第三個標(biāo)簽添加到圖例中?
添加回答
舉報
0/150
提交
取消