Seaborn: Wrong legend when using line-style with relplot

Created on 8 Sep 2018  路  1Comment  路  Source: mwaskom/seaborn

This example relplot call produces the wrong legend. In the example, both the legend of the variables used for hue and style are depicted as the line-style, instead of having one legend part for the color and the other for the style:

# Testdata
data = pd.DataFrame([(0, 0, 0, 0),
                     (0, 0, 1, 1),
                     (0, 1, 0, 1),
                     (0, 1, 1, 0),
                     (1, 0, 0, 0),
                     (1, 0, 1, 0),
                     (1, 1, 0, 1),
                     (1, 1, 1, 1)],
                    columns=['a', 'b', 'x', 'y'])
sns.relplot(x='x', y='y', hue='a', style='b', kind='line', data=data)



md5-b2dec66e62a8ea7622dc51e79ea12934



sns.lineplot(x='x', y='y', hue='a', style='b', data=data)

I tested this with python 3.5.2 and seaborn 0.9.0.

bug

Most helpful comment

Yep this is a bug in FacetGrid. It predates and did not anticipate having multiple semantic variables in the legend. The problem is that it manages its legend data with a dictionary where the keys are values names. I intend to fix it for a 0.9.1 release but it will take a little bit of work with some care in not breaking other things.

Unfortunately I'm not aware of a great workaround when level names are shared across the semantic variables. I guess if you have string-typed levels you could add trailing spaces to differentiate them. Annoying, I know.

>All comments

Yep this is a bug in FacetGrid. It predates and did not anticipate having multiple semantic variables in the legend. The problem is that it manages its legend data with a dictionary where the keys are values names. I intend to fix it for a 0.9.1 release but it will take a little bit of work with some care in not breaking other things.

Unfortunately I'm not aware of a great workaround when level names are shared across the semantic variables. I guess if you have string-typed levels you could add trailing spaces to differentiate them. Annoying, I know.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

btyukodi picture btyukodi  路  3Comments

sungshine picture sungshine  路  3Comments

JanHomann picture JanHomann  路  3Comments

sofiatti picture sofiatti  路  4Comments

wenhaosun picture wenhaosun  路  3Comments