question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

pairplot fails with hue_order not containing all hue values in seaborn 0.11.1

See original GitHub issue

In seaborn < 0.11, one could plot only a subset of the values in the hue column, by passing a hue_order list containing only the desired values. Points with hue values not in the list were simply not plotted.

iris = sns.load_dataset("iris")`
# The hue column contains three different species; here we want to plot two
sns.pairplot(iris, hue="species", hue_order=["setosa", "versicolor"])

This no longer works in 0.11.1. Passing a hue_order list that does not contain some of the values in the hue column raises a long, ugly error traceback. The first exception arises in seaborn/_core.py:

TypeError: ufunc 'isnan' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

seaborn version: 0.11.1 matplotlib version: 3.3.2 matplotlib backends: MacOSX, Agg or jupyter notebook inline.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:3
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mwaskomcommented, Jan 6, 2021

Easiest workaround is probably

hue_order = ["setosa", "versicolor"]
sns.pairplot(iris.query("species in @hue_order"), hue="species", hue_order=hue_order)
0reactions
mwaskomcommented, Jun 11, 2022

Closed with #2848

Read more comments on GitHub >

github_iconTop Results From Across the Web

seaborn.pairplot — seaborn 0.12.1 documentation - PyData |
If a dict, keys should be values in the hue variable. varslist of variable names. Variables within data to use, otherwise use every...
Read more >
Seaborn pairplot hue parameter not working as expected
By default, seaborn will show all numeric columns! So if your 'hue' column ('C' in your case) column as string(object) type, it will...
Read more >
Seaborn Pairplot in Detail| Python Seaborn Tutorial
Seaborn Pairplot uses to get the relation between each and every variable present in Pandas DataFrame. It works like a seaborn scatter plot....
Read more >
python - Adding another 'hue' to a pairplot
I have plotted a pairplot in Seaborn with a hue, similar to the one shown below. I would like to add another hue...
Read more >
How to make a pairplot in Python and the Seaborn ... - YouTube
This Seaborn paiplot video covers how to make a pairplot with Seaborn Python as well as the Seaborn pairplot interpretation.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found