PLOTS twoYaxesΒΆ

# -*-Python-*-
# Created by bgrierson at 15 Dec 2016  05:08

# Create two data sets with largely different scales
x = linspace(0, 1, 21)
y1 = np.sin(2.0 * np.pi * x) + 1.0
y2 = 10.0 * np.cos(2.0 * np.pi * x)

# Plot the first data set and set the tick labels to the color of the plot
fig, ax = plt.subplots()
ax.plot(x, y1, color='b', label='Data 1')
for tl in ax.get_yticklabels():
    tl.set_color('b')
ax.legend(loc='lower right')

# Make the second plot by setting the x-axis to "twin"
ax2 = ax.twinx()
ax2.plot(x, y2, color='g', label='Data 2')
for tl in ax2.get_yticklabels():
    tl.set_color('g')
ax2.legend(loc='upper right')