I can add a y label to the left y-axis using plt.ylabel
, but how can I add it to the secondary y-axis?
JavaScript
x
6
1
table = sql.read_frame(query,connection)
2
3
table[0].plot(color=colors[0],ylim=(0,100))
4
table[1].plot(secondary_y=True,color=colors[1])
5
plt.ylabel('$')
6
Advertisement
Answer
The best way is to interact with the axes
object directly
JavaScript
1
18
18
1
import numpy as np
2
import matplotlib.pyplot as plt
3
x = np.arange(0, 10, 0.1)
4
y1 = 0.05 * x**2
5
y2 = -1 *y1
6
7
fig, ax1 = plt.subplots()
8
9
ax2 = ax1.twinx()
10
ax1.plot(x, y1, 'g-')
11
ax2.plot(x, y2, 'b-')
12
13
ax1.set_xlabel('X data')
14
ax1.set_ylabel('Y1 data', color='g')
15
ax2.set_ylabel('Y2 data', color='b')
16
17
plt.show()
18