Reputation: 21961
I am using seaborn facetgrid in combination with lineplot to produce:
Is there a way to change legend order from Average, Good, Poor to Poor, Average, Good and assign the color red to Poor and the color green to Good?
Upvotes: 2
Views: 3904
Reputation: 96
Building off of Quang Hoang's Answer, you can also add the keyword pallete
to control the colors:
orders = ['Poor', 'Average', 'Good']
palette = {'Poor': 'red', 'Average': 'blue', 'Good': 'green'}
arg = ['val', 'date', 'Condition']
(sns.FacetGrid(df, col='Year', col_wrap=1, height=5)
.map(sns.lineplot, *arg, hue_order=orders, palette=palette)
.add_legend()
.set_titles("{col_name}")
)
Upvotes: 1
Reputation: 150735
You can pass a hue_order
to map
:
orders = ['Poor', 'Average', 'Good']
arg = ['val', 'date', 'Condition']
(sns.FacetGrid(df, col='Year', col_wrap=1, height=5)
.map(sns.lineplot, *arg, hue_order=orders)
.add_legend()
.set_titles("{col_name}")
)
Upvotes: 1