7

我曾经stem_graphic绘制茎叶图并将其保存为 pdf,但是在尝试输入标题时出现错误:Figure object have no attribute set_title

ax, b=stem_graphic(mileage['disp'])
ax.set_title("Vicky")


This is the error
Traceback (most recent call last):
File "<pyshell#214>", line 1, in <module>
ax.set_title("Vicky")
AttributeError: 'Figure' object has no attribute 'set_title'
4

2 回答 2

6

看起来您的stem_graphic函数返回一个matplotlib.figure对象,因此您应该使用该suptitle()方法添加标题。

尝试:

fig, b = stem_graphic(mileage['disp'])
fig.suptitle("Vicky")
于 2017-06-28T20:10:44.427 回答
0

stem_graphicstemgraphic 包中的函数返回一个图形和一个轴;文档字符串状态

:return: matplotlib 图和轴实例

因此,代码应该看起来像

fig, ax =stem_graphic(mileage['disp'])
ax.set_title("Vicky")
于 2017-06-28T20:21:50.647 回答