使用辅助 y 轴时如何标记 y 轴? [英] How to label y-axis when using a secondary y-axis?
本文介绍了使用辅助 y 轴时如何标记 y 轴?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图标记两个 y 轴,一个表示WLL",另一个表示S&P 500".现在,我只能标记次要 y 轴(标准普尔 500 指数).
I am trying to label both y-axis, one to say "WLL", the other to say "S&P 500". Right now, I can only label the secondary y-axis (S&P 500).
import pandas as pd
from pandas import DataFrame
from matplotlib import pyplot as plt
import pandas.io.data as web
import datetime as dt
start = '2013-01-01'
end = dt.datetime.today()
df = web.DataReader('WLL', 'yahoo', start, end)
sp = web.DataReader('^GSPC', 'yahoo', start, end)
fig, ax1 = plt.subplots()
df['Close'].plot(ax=ax1,color='g',linewidth=1.0)
sp['Close'].plot(secondary_y=True, ax=ax1,color='b',linewidth=1.0)
ax = df['Close'].plot(); sp['Close'].plot(ax=ax, secondary_y=True)
plt.xlabel('xlabel', fontsize=10)
plt.ylabel('ylabel', fontsize=10)
plt.show()
推荐答案
这可以通过在绘制辅助 y-axis
之前设置标签来实现.
This can be achieved be setting the label before plotting the secondary y-axis
.
fig, ax1 = plt.subplots()
df['Close'].plot(ax=ax1, color='g', linewidth=1.0)
sp['Close'].plot(secondary_y=True, ax=ax1, color='b', linewidth=1.0)
ax = df['Close'].plot();
ax.set_ylabel('WLL', fontsize=10);
sp['Close'].plot(ax=ax, secondary_y=True);
plt.xlabel('xlabel', fontsize=10)
plt.ylabel('S&P 500', fontsize=10, rotation=-90)
这篇关于使用辅助 y 轴时如何标记 y 轴?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文