I have 4 columns in a dataframe: Country, City, Year and Temperature. I want to make plot as I did with this command:
g =sns.FacetGrid(grouped,col='Country',hue='City', col_wrap=3)
g = g.map(plt.plot,"year", "AverageTemperatureCelsius")
Now I can add a legend with:
g.add_legend(title='$\\bf{City}$',handlelength=1,prop={'size': 16})
Resulting in a plot like this:
But I want legend to be countries, meaning I would like the labels to be:
label=['Brazil', 'France', 'Japan', 'New Zealand', 'Poland', 'South Africa','Sweden', 'Ukraine']
And at each subplot there would be one colour, how can I achieve that?
The result I am after:
Setting hue=None
should both make all of the subplots the same color, and change the legend to display your column data instead.
The 'hue' argument selects a subset of your data to emphasize in the subplots, docs here .
Edit: if you want to keep the hue parameter, but have it plot all the same colors, you can use keyword arguments.
colors = {'colors': ['b']}
g =sns.FacetGrid(grouped,col='Country',hue='City',hue_kws= colors, col_wrap=3)
To then fix the legend, this answer puts it really nicely.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.