second y axis matplotlib

Solutions on MaxInterview for second y axis matplotlib by the best coders in the world

showing results for - "second y axis matplotlib"
Emmanuel
18 May 2017
1import numpy as np
2import matplotlib.pyplot as plt
3x = np.arange(0, 10, 0.1)
4y1 = 0.05 * x**2
5y2 = -1 *y1
6
7fig, ax1 = plt.subplots()
8
9ax2 = ax1.twinx()
10ax1.plot(x, y1, 'g-')
11ax2.plot(x, y2, 'b-')
12
13ax1.set_xlabel('X data')
14ax1.set_ylabel('Y1 data', color='g')
15ax2.set_ylabel('Y2 data', color='b')
16
17plt.show()