Incorrect legend in lineplot when using numeric values in hue
See original GitHub issueI believe this is related to #1560 but happens even when style
is not used and gives incorrect behaviour with lineplot
.
Here’s an example. The legend should have two items, 0.2 and 0.3
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
df = pd.DataFrame(
[
[0, 0, .2],
[1, 1, .2],
[2, 2, .2],
[0, 0.5, .3],
[1, 1.5, .3],
[2, 2.5, .3],
],
columns=['x','y','hue']
)
sns.lineplot(data=df, x='x', y='y', hue='hue')
plt.show()
Interestingly it works if the hue
column contains strings or integers as the categorical value rather than floats. I guess casting that column to a string could be a workaround in the meantime.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:11
- Comments:9
Top Results From Across the Web
Is this an error in the seaborn.lineplot hue parameter?
This is a known bug of seaborn when the hue can be cast to integers. You could add a prefix to the hue...
Read more >seaborn.lineplot — seaborn 0.12.1 documentation - PyData |
If “brief”, numeric hue and size variables will be represented with a sample of evenly spaced values. If “full”, every group will get...
Read more >seaborn.lineplot() method in Python - GeeksforGeeks
Syntax : sns. · Parameters: · x, y: Input data variables; must be numeric. · hue: Grouping variable that will produce lines with...
Read more >Beautifying the Messy Plots in Python & Solving Common ...
sns.countplot(x = 'method', hue = 'number, data = df2) ... We can override the legend setting using Matplotlib. bbox_to_anchor allows you to ...
Read more >seaborn.lineplot — seaborn 0.9.0 documentation
If “brief”, numeric hue and size variables will be represented with a sample of evenly spaced ... If False , no legend data...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
My current work-around is to convert the hue entries into strings that will not be reinterpreted as something else. e.g.,
where the
$...$
is a hack (with the side-effect of rendering the number in LaTeX) that prevents:Other schemes such as
"= %s" % x
also work.Just set legend=‘full’ in the call to seaborn lineplot