【问题标题】:Trouble using factorplot method of Seaborn使用 Seaborn 的 factorplot 方法时遇到问题
【发布时间】:2019-09-28 08:47:23
【问题描述】:

我正在尝试运行 Python 笔记本 (link)。在In [18]: 行,作者使用Seaborn 绘制了一些数据,我遇到了一个错误

ValueError: 'c' 参数有 12 个元素,不能与大小为 0 的 'x' 和大小为 0 的 'y' 一起使用。

在 [18] 中:

import seaborn as sns

# sales trends
sns.factorplot(data = train_store, x = 'Month', y = "Sales", 
               col = 'StoreType', # per store type in cols
               palette = 'plasma',
               hue = 'StoreType',
               row = 'Promo', # per promo in the store in rows
               color = c)

Seaborn 版本:

seaborn==0.9.0

我在网上查看了有关此错误的信息,但找不到任何有用的信息。请指引我正确的方向。

更新

这是用于测试的最少代码

import pickle
import seaborn as sns
# seaborn==0.9.0

with open('train_store', 'rb') as f:
    train_store = pickle.load(f)

c = '#386B7F' # basic color for plots

# sales trends
sns.factorplot(data = train_store, x = 'Month', y = "Sales", 
               col = 'StoreType', # per store type in cols
               palette = 'plasma',
               hue = 'StoreType',
               row = 'Promo', # per promo in the store in rows
               color = c)

train_store 数据文件链接:Link 1

【问题讨论】:

  • 你能创建一个minimal reproducible example吗?
  • 如果省略color=c,输出会是什么?潜在问题可能是 #14113,但在下一个 seaborn 版本出现之前可能没有任何修复。
  • @DavidG 您好,我已经创建了用于测试的最小代码,您可以查看更新后的问题以获取更多详细信息
  • @ImportanceOfBeingErnest 您好,我已尝试删除color=c,但仍然出现相同的错误

标签: python ubuntu seaborn kaggle


【解决方案1】:

这是 0.9.0 版带来的更改。

在这个版本中,factorplot 已被(隐式)弃用,新的​​ catplot(类别图)已实施。您仍然可以在代码中使用 factorplot,但在内部它会使用相关参数调用 catplot。

在 catplot 实现中,当使用类型“点”(带有表示组平均值的点的线)时,我们不能将“色调”和“科尔”或“色调”和“行”作为相同的数据字段。

因此,您可以将代码更改为以下任一选项:

选项 1:

sns.catplot(x="Month", y="Sales", hue="StoreType",col="Promo", kind="point", data=train_store)

选项 2:

sns.factorplot(data = train_store, x = 'Month', y = "Sales",col = 'Promo',hue = 'StoreType') 

【讨论】:

    【解决方案2】:

    我必须进行以下更改才能解决问题

    sns.factorplot(data = train_store, x = 'Month', y = "Sales", 
                   row = 'Promo',     # per promo in the store in rows
                   col = 'StoreType' # per store type in cols
                   )
    

    【讨论】:

      【解决方案3】:

      我做了这个简单的改变,得到了想要的地块

      sns.factorplot(data = train_store, x = 'DayOfWeek', y = "Sales", 
                     col = 'Promo', 
                     row = 'Promo2')
      

      我只是丢弃了色调和调色板参数。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-01-02
        • 1970-01-01
        • 2016-09-19
        • 2013-10-29
        • 2017-12-14
        • 2014-10-05
        • 1970-01-01
        • 2016-05-12
        相关资源
        最近更新 更多