使用 Seaborn 的 factorplot 方法时遇到问题
Trouble using factorplot method of Seaborn
我正在尝试 运行 一个 Python 笔记本 (link)。在第 In [18]:
行,作者使用 Seaborn
绘制了一些数据,我收到一个错误
ValueError: 'c' argument has 12 elements, which is not acceptable for use with 'x' with size 0, 'y' with size 0.
在[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)
Link 到 train_store 数据文件:Link 1
这是版本 0.9.0 带来的变化。
在此版本中,factorplot 已被弃用(隐含地),新的 catplot(类别图)已实现。您仍然可以在代码中使用 factorplot,但在内部它会使用相关参数调用 catplot。
在 catplot 实现中,当使用类型 'point'(行点代表组的平均值)。
因此,您可以将代码更改为以下任一选项:
选项 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')
我必须进行以下更改才能解决此问题
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
)
我做了这个简单的改动并得到了想要的图
sns.factorplot(data = train_store, x = 'DayOfWeek', y = "Sales",
col = 'Promo',
row = 'Promo2')
我刚刚丢弃了色调和调色板参数。
我正在尝试 运行 一个 Python 笔记本 (link)。在第 In [18]:
行,作者使用 Seaborn
绘制了一些数据,我收到一个错误
ValueError: 'c' argument has 12 elements, which is not acceptable for use with 'x' with size 0, 'y' with size 0.
在[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)
Link 到 train_store 数据文件:Link 1
这是版本 0.9.0 带来的变化。
在此版本中,factorplot 已被弃用(隐含地),新的 catplot(类别图)已实现。您仍然可以在代码中使用 factorplot,但在内部它会使用相关参数调用 catplot。
在 catplot 实现中,当使用类型 'point'(行点代表组的平均值)。
因此,您可以将代码更改为以下任一选项:
选项 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')
我必须进行以下更改才能解决此问题
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
)
我做了这个简单的改动并得到了想要的图
sns.factorplot(data = train_store, x = 'DayOfWeek', y = "Sales",
col = 'Promo',
row = 'Promo2')
我刚刚丢弃了色调和调色板参数。