首页 > 解决方案 > AttributeError:将 ytickslabels 设置为摄氏度时,模块“matplotlib.pyplot”没有属性“set_ytickslabels”

问题描述

我正在尝试通过使用以摄氏度为单位在 y 轴刻度上设置我的值

plt.get_yticks=np.arange(-40,40,10)
plt.set_ytickslabels('{}C'.format('\u00b0'))

我知道我可能在 set_ytickslabels 中做错了?

我之前的代码:`

plt.figure(figsize=(10,6))
ax = plt.gca()
plt.plot(dates, df1['Values'], '-b',dates, df2['Values'], '-r')
ax.set_xlim(dates[0],dates[364])

这给出了错误消息。如果我更改为ax.set_ytickslabels('{}C'.format('\u00b0')),我会收到相同的错误消息,'AttributeError: 'AxesSubplot' object has no attribute 'set_ytickslabels')

<ipython-input-35-bc07fa12bc0e> in <module>()
     46 #ax.set_yticklabels(maxtemp15['MaxRecord15']{}C.format('\u00b0'))
     47 #ax.set_yticklabels(map(lambda x: '{:}$^\circ$C'.format(x),ax.get_yticks()))
---> 48 plt.set_ytickslabels('{}C'.format('\u00b0'))

AttributeError: module 'matplotlib.pyplot' has no attribute 'set_ytickslabels'

我的情节

标签: pythonmatplotlib

解决方案


推荐阅读