【问题标题】:Seaborn FacetGrid errorSeaborn FacetGrid 错误
【发布时间】:2019-01-02 05:25:33
【问题描述】:

this page 上的示例启发,我想使用具有 6 个面的鸢尾花数据集制作一个 seaborn facetgrid:3 种 x 2 种类型(花瓣或萼片)。在每个方面,我都需要一个长度(或宽度)的直方图。

但我尝试的代码给出了ValueError: color kwarg must have one color per dataset

有什么建议可以解决这个问题吗?

import pandas as pd
import matplotlib.pyplot as ply
import seaborn as sns
iris = sns.load_dataset('iris')
iris_petal = pd.DataFrame(iris.iloc[:,-3:].values, columns=['length', 'width', 'species'])
iris_petal['type'] = 'petal'
iris_sepal = pd.DataFrame(iris.iloc[:,[0, 1, -1]].values, columns=['length', 'width', 'species'])
iris_sepal['type'] = 'sepal'
iris = pd.concat([iris_sepal, iris_petal])
iris.sample(n=10)
g = sns.FacetGrid(iris, col="species",  row="type")
g = g.map(plt.hist, "length", color = 'b')

【问题讨论】:

  • 奇怪的是,即使你在代码中省略了color = 'b',也会发生这个错误(加上那行,错误是有道理的,对吧?)。
  • 问题是数值列的数据类型是object。我不知道为什么会这样,但如果你修复它应该可以工作。
  • 谢谢,我没有注意到,但它解决了问题!你能写下这个答案,以便我将其标记为正确吗?
  • 随时提供您自己的答案。我现在真的没有时间。

标签: python seaborn


【解决方案1】:

正如@ImportanceOfBeingErnest 提到的,这是一个数据类型问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-03
    • 1970-01-01
    • 2019-08-02
    • 2015-11-14
    • 1970-01-01
    • 2019-01-23
    相关资源
    最近更新 更多