繁体   English   中英

模块“matplotlib.pyplot”没有属性“yaxis”

[英]module 'matplotlib.pyplot' has no attribute 'yaxis'

我知道这是不可重现的,但我不确定发生了什么才能做到这一点。 如果有人可以解释,我会更新并重新回答。

ax = plt.plot( 'spending_billions', 'poverty_rates', data=pv_rates_df, marker='o', color='blue', linewidth=2, label = 'Black Poverty Rate')
plt.title("Black Poverty and Cash Reparations", fontsize=12, fontweight=0, color='Black')
plt.xlabel("Spending in Billions")
plt.ylabel("SPM Black Poverty Rates")
plt.yticks(np.arange(0, 22, 2))
plt.yaxis.set_major_formatter(mtick.PercentFormatter())
plt.legend()

我得到这个错误。 模块“matplotlib.pyplot”没有属性“yaxis”

有什么建议么?

如错误消息所述,您的plt yaxis上不存在 yaxis。

If you use pandas.DataFrame.plot , the return value is in fact matplotlib.axes.Axes , as your variable naming suggests. 但是,您似乎正在使用matplotlib.pyplot.plot ,它返回matplotlib.lines.Line2D对象的列表。

yaxismatplotlib.axes.Axes的一个属性。 要获取您当前的matplotlib.axes.Axes实例,您可以使用matplotlib.gca() (获取当前轴)。 所以以下工作:

import matplotlib.pyplot as plt
import matplotlib.ticker as ticker

plt.scatter(range(5), range(5), s=3)
plt.gca().yaxis.set_major_formatter(ticker.PercentFormatter())
plt.show()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM