我被返回了BarContainer' object has no attribute 'get_height'
时间: 2023-10-15 22:07:37 浏览: 56
这个错误通常是因为你在使用一个不支持 `get_height()` 方法的对象调用了 `get_height()` 方法。
通常情况下,`get_height()` 方法是在绘制柱状图、条形图等图表时使用的。如果你遇到这个错误,可能是因为你在其他类型的对象上调用了 `get_height()` 方法,比如说一个容器对象。
要解决这个问题,你需要检查你的代码,找出在哪里调用了 `get_height()` 方法,并确认这个方法确实可以被调用。如果你不确定如何修改代码,请提供更多的上下文和相关代码,我可以帮你更好地理解和解决这个问题。
相关问题
BarContainer' object has no attribute 'get_height'
抱歉,我之前的回答有误。在 `seaborn` 库中,`barplot` 函数返回的是一个 `AxesSubplot` 对象,而不是一个 `BarContainer` 对象。因此,需要使用 `patches` 属性来获取每个柱子的信息,然后使用 `get_height()` 函数获取每个柱子的高度。
具体的代码如下:
```python
import seaborn as sns
# 加载数据集
tips = sns.load_dataset("tips")
# 绘制柱状图
ax = sns.barplot(x="day", y="total_bill", data=tips)
# 在每个柱子上添加数据标签
for p in ax.patches:
ax.annotate("%.2f" % p.get_height(), (p.get_x() + p.get_width() / 2., p.get_height()),
ha='center', va='center', fontsize=11, color='gray', xytext=(0, 5),
textcoords='offset points')
```
在上面的代码中,`ax.patches` 获取每个柱子的信息,`p.get_x()` 和 `p.get_width()` 获取柱子的位置和宽度,`p.get_height()` 获取柱子的高度,`ax.annotate()` 函数在每个柱子上添加数据标签。
在 `ax.annotate()` 函数中,`"%.2f" % p.get_height()` 表示保留两位小数的柱子高度,`xytext=(0, 5)` 表示数据标签相对于柱子顶部偏移 5 个像素,`textcoords='offset points'` 表示 `xytext` 是相对于偏移量的像素坐标。
运行上面的代码,即可在 `seaborn` 库中的柱状图上添加数据标签。
socreboard object has no attribute get_rect
引用:AttributeError: 'int' object has no attribute '_get_axis' 。 引用:get_rect()应该是pygame中的一种方法,为什么不能使用?而是被当成Group()中的变量 。 引用:alien.rect.y = alien.rect.height 2 * alien.rect.height * row_number 。
根据提供的引用内容,出现了'scoreboard'对象没有'get_rect'属性的错误。这个错误表明在'scoreboard'对象上调用了'get_rect'方法,但是这个方法在这个对象中并不存在。