I know this isn't reproducable but I'm not sure enough what is happening to make it that way. I'll update and re-answer if someone can explain.
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()
I get this error. module 'matplotlib.pyplot' has no attribute 'yaxis'
Any suggestions?
As the error message says, yaxis
does not exist on your plt
object.
If you use pandas.DataFrame.plot
, the return value is in fact matplotlib.axes.Axes
, as your variable naming suggests. It seems however that you're using matplotlib.pyplot.plot
, which returns a list of matplotlib.lines.Line2D
objects.
yaxis
is an attribute of matplotlib.axes.Axes
. To get your current matplotlib.axes.Axes
instance, you can use matplotlib.gca()
(get current axes). So the following works:
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()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.