在下图中,如何对图例进行排序以在“是”上方显示“否”?谢谢
import pandas as pd
import seaborn as sb
from matplotlib import pyplot as plt
df = sb.load_dataset('tips')
g = sb.FacetGrid(df, col='sex', hue='smoker', col_wrap=2)
g.map(plt.scatter, 'total_bill', 'tip', alpha=.7)
g.axes[-1].legend()
plt.show()
答案 0 :(得分:2)
'smoker'
列设置为pandas.Categorical
类别import seaborn as sns
import pandas as pd
import matplotlib.pyplot as plt
df = sns.load_dataset('tips')
# set smoker as categorical and ordered
df.smoker = pd.Categorical(df.smoker, categories=['No', 'Yes'], ordered=True)
# plot
g = sns.FacetGrid(df, col='sex', hue='smoker', height=5, col_wrap=2)
g.map(plt.scatter, 'total_bill', 'tip', alpha=.7)
g.axes[-1].legend()
plt.show()