Skip to content
Advertisement

Set line widths according to column for seaborn FacetGrid with lineplot

I would like to pick out a certain line in each lineplot in a FacetGrid, to highlight the “default” setting compared to the other options.

I’ve tried to make a minimal example based on this random walk example in the seaborn documentation

JavaScript

This gives me faceted line plots with all lines the same width (of course):

first attempt

I have created an extra column called importance; I would like the line width to be set according to this column. I can see that with a simple seaborn.lineplot you can “Assign the size semantic to map the width of the lines with a numeric variable”. I have tried to use size= in the FacetGrid() call and in the map_dataframe() call, but it’s not working.

For example, if I use this instead:

JavaScript

I see no difference in line thickness, but now the legend is messed up too:

second attempt

Advertisement

Answer

Your problem is that importance is the same in a given hue level, and that sizes seem to be normalized at the levels of hue, so they end up being all the same. You can, however, pass a mapping dictionary to sizes= to match a given size to a particular linewidth

JavaScript
JavaScript
JavaScript

enter image description here

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement