How to label y-axis when using a secondary y-axis?
Edited to use pandas datareader instead of pandas.io
This can be achieved be setting the label before plotting the secondary y-axis
.
from matplotlib import pyplot as plt
import pandas as pd
import pandas_datareader.data as web
from matplotlib import pyplot as plt
import datetime as dt
# Get data.
start = '2013-01-01'
end = dt.datetime.today()
df = web.DataReader('WLL', 'yahoo', start, end)
sp = web.DataReader('^GSPC', 'yahoo', start, end)
# Plot data.
ax = df['Close'].plot(ylabel='WLL', fontsize=10)
sp['Close'].plot(ax=ax, secondary_y=True)
plt.ylabel('S&P 500', fontsize=10, rotation=-90)
plt.show()
just add right_ax before set_ylabel()
like so:
ax.right_ax.set_ylabel()