python - Seaborn 'Could not interpret input' 错误

标签 python seaborn facet-grid

我读过引发类似异常的帖子(即: herethere ),但不是特别有用,因为该错误基本上是由于拼写错误造成的。

下面是引发我的错误的非常简单的代码。阅读seaborn文档和示例没有帮助。

import pandas
import seaborn
df=pandas.DataFrame([[0,25.0,100],[0,24.0,95],[0,25.6,90],[0,20,120],[0,21,130],[0,22.5,115],[1,25.0,100],[1,26.0,150],[1,24.0,120],[1,20.0,200],[1,15.0,250]], columns=["meter","T°@T","meter-reading"])
df

输出:

meter   T°@T    meter-reading
0   0   25.0    100
1   0   24.0    95
2   0   25.6    90
3   0   20.0    120
4   0   21.0    130
5   0   22.5    115
6   1   25.0    100
7   1   26.0    150
8   1   24.0    120
9   1   20.0    200
10  1   15.0    250

然后尝试绘制 FacetGrid:

g=seaborn.FacetGrid(data=df, col="meter").map(seaborn.relplot, x="T°@T",y="meter-reading")


Error: Could not interpret input 'T°@T'

非常奇怪的是,.map 遇到问题,但其他代码工作得很好:

seaborn.relplot(data=df,x="T°@T",y="meter-reading")

我做错了什么?

PS:Jupyter Notebook 和 Spyder 中都会引发异常

最佳答案

我猜这是一个错误,因为 relplot 本身可以展开多个图表。因此,您可以通过指定sns.scatterplot来绘制图表。我不认为“meter”是用颜色编码的,因为它不是类别变量。

import matplotlib.pyplot as plt
import seaborn as sns

g = sns.FacetGrid(data=df, col="meter")
g.map_dataframe(sns.scatterplot, x=df["T°@T"], y=df["meter-reading"], hue='meter') 
g.set_axis_labels('T°@T','meter-reading')
g.add_legend()

enter image description here

关于python - Seaborn 'Could not interpret input' 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64463405/

相关文章:

Python 脚本等待某个程序启动,然后启动另一个程序。 ( Windows )

python - 使用seaborn.pairplot()

r - 将参数传递给函数 -ggplot 中的刻面网格

r - 将因素分成多个方面?

r - 面网格导致 R 中不同的行高

python - 在 Jupyter 笔记本中使用 PySpark 时如何包含外部 Spark 库

python - 如何使用 Python 下载有效的 Youtube 视频 HTML 页面?

python - 如何将查询列表传递给 pandas 数据框,并输出结果列表?

python - Seaborn 热图不断在数据集上循环添加颜色条

python - 显示字典中的 seaborn 图