Skip to content

Passing 'c=cols' to pairplot/PairGrid causes ValueError - it would be nice to be more flexible #1301

@jbrinchmann

Description

@jbrinchmann

There is a conflict in seaborn when one tries to colour points in a pairplot using a continuous colour scale - while a work-around exists, this is such a common case it would be nice if it was directly handled by the code. A simple example is:

y = np.random.normal(-2, 4, size=100)
z = np.abs(x)*y
T = x*y
df = pd.DataFrame({'x': x, 'y': y, 'z': z, 'T': T})
sns.pairplot(df, plot_kws=dict(c= T))

which fails with ValueError: Supply a 'c' kwarg or a 'color' kwarg but not both; they differ but their functionalities overlap.

This seems to be caused by a call in axisgrid.py:
func(data_k[x_var], data_k[y_var], label=label_k, color=color, **kwargs)
which always passes in the color keyword.

It would be desirable to inspect the kwargs option, and if c= is not provided, to pass color in as keyword.

Now as a work-around it is of course possible to wrap plt.scatter explicitly with say

def colplot(x, y, color, **kwargs):
    plt.scatter(x, y, c=color, **kwargs)

but this is not obvious from the documentation and as I would expect this to be a fairly common use case it would be nice with a more flexible handling of continous colour variables, in line with how poweful seaborn in general is out of the box.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions