arush1836
arush1836

Reputation: 1547

Trouble using factorplot method of Seaborn

I am trying to run a Python notebook (link). At line In [18]: where author plot some data using Seaborn I am getting an error

ValueError: 'c' argument has 12 elements, which is not acceptable for use with 'x' with size 0, 'y' with size 0.

In [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 Version:

seaborn==0.9.0

I looked at the web about this error but couldn't find anything useful. Please guide me in the right direction.

Update

Here is the minimal code for testing

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 to train_store data file: Link 1

Upvotes: 1

Views: 4351

Answers (3)

Sca
Sca

Reputation: 195

I made this simple change and got the desired plots

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

I just discarded hue and pallete parameters.

Upvotes: 0

arush1836
arush1836

Reputation: 1547

I had to make following changes in order to fix the issue

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
               )

Upvotes: 0

tango.with.data
tango.with.data

Reputation: 36

This is a change brought in with version 0.9.0.

In this version, factorplot is deprecated (implicitly) and the new catplot (category plot) has been implemented. You can still use factorplot in your code, but internally it will invoke catplot with the relevant arguments.

In catplot implementation, we cannot have 'hue' and 'col' or 'hue' and 'row' as same data fields when using the kind 'point' (line with points representing the mean value for the group).

Hence, you can change your code to either of the following options:

option 1:

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

option 2:

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

Upvotes: 2

Related Questions