Skip to content

PariGrid map_diag does not preserve category ordering #1663

@wmayer7

Description

@wmayer7

PairGrid.map_diag does not preserve the order specified for ordered categorical columns in a pandas DataFrame. (I'm using seaborn 0.9.0 and pandas 0.24.0.)

In the following example, the diagonal axes for the count plots use order a,b,c and d,e,f instead of the category order c,a,b and f,e,d, respectively.

import pandas as pd
import seaborn as sns

X = pd.Categorical(["a", "b", "c", "a"], categories=["c", "a", "b"], ordered=True)
Y = pd.Categorical(["d", "e", "f", "e"], categories=["f", "e", "d"], ordered=True)
df = pd.DataFrame(dict(X=X,Y=Y))
g = sns.PairGrid(df, vars=df.columns)
g.map_diag(sns.countplot)

Could the pandas Series/Group object be passed to the plotting function (instead of converting it to a numpy array) to preserve the full data type information associated with each pandas column?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions