python - ValueError:无法将输入数组从形状(244,2)广播到形状(244,)
问题描述
我正在尝试绘制一个简单的 Seaborn 情节。
import seaborn as sns
from matplotlib import pyplot as plt
tips = sns.load_dataset('tips')
#Plotting our subplots dividing with smoker
sns.relplot(x = "total_bill", y = "tip", hue = "smoker", col = "size", data = tips)
#Showing our plots in a proper format
plt.show()
但它显示一个错误
ValueError: could not broadcast input array from shape (244,2) into shape (244,)
我该怎么办?
解决方案
'size' 列名似乎有一个错误。这很奇怪,因为tips
它是 seaborn 的典型示例数据集之一。
当该列被重命名时,它按预期工作:
import seaborn as sns
from matplotlib import pyplot as plt
tips = sns.load_dataset('tips')
tips.rename(columns={'size': 'size_renamed'}, inplace=True)
sns.relplot(x='total_bill', y='tip', hue='smoker', col='size_renamed', data=tips)
plt.tight_layout()
plt.show()
推荐阅读
- python - 可以使用中央资源文件在所有测试用例中导入多个库和关键字文件可能会导致执行期间出现性能问题
- c++ - 将两个不同的类对象向量排序在一起
- java - 如果列表项在一个变量中具有相同的值,则使用不同的变量比较列表
- java - 多模块Maven项目中的JAXBContext缓存
- ios - 使用带有自定义单元格和下一个按钮的 TableView 在数组中加载下一个问题
- r - 简单的功能动画
- php - 如何修复这个查询,php?
- mysql - Mysql 事件在早上 7 点到下午 6 点之间每 5 分钟运行一次
- mule - mule : Scatter Gather : 如果我们在 Scatter gather 组件中设置目标变量,如何聚合来自不同路由的变量?
- pytest - 是否可以定义 pytest“测试套件”(具有不同的 addopts)?