如何在Seaborn中控制图例-Python
问题内容:
我正在尝试查找有关如何控制和自定义Seaborn地块中图例的指南,但我找不到任何指南。
为了使问题更具体,我提供了一个可重现的示例:
surveys_by_year_sex_long
year sex wgt
0 2001 F 36.221914
1 2001 M 36.481844
2 2002 F 34.016799
3 2002 M 37.589905
%matplotlib inline
from matplotlib import *
from matplotlib import pyplot as plt
import seaborn as sn
sn.factorplot(x = "year", y = "wgt", data = surveys_by_year_sex_long, hue = "sex", kind = "bar", legend_out = True,
palette = sn.color_palette(palette = ["SteelBlue" , "Salmon"]), hue_order = ["M", "F"])
plt.xlabel('Year')
plt.ylabel('Weight')
plt.title('Average Weight by Year and Sex')
在此示例中,我希望能够将M定义为Male,将F定义为Female,而不是将sex用作图例的标题。
您的建议将不胜感激。
问题答案: