根据x轴刻度标签为FacetGrid对象创建第二个图例

时间:2020-02-27 10:59:48

标签: python matplotlib seaborn

我使用sns.catplot()绘制数据框,其中x轴刻度标签是整数的递增数。我想在图中添加第二个图例,以基于字符串列表描述这些x轴刻度标签。

示例:

import numpy as np
import pandas as pd
import seaborn as sns

# simulate data
np.random.seed(42)
measure_names = np.tile(np.repeat(['Train BAC','Test BAC','Train SPEC','Test SPEC'],10),2)
model_numbers = np.repeat([0,1],40)
measure_values = np.random.uniform(low=0,high=1,size=80).tolist()
plot_df = pd.DataFrame({'model_number':model_numbers,
                        'measure_name':measure_names,
                        'measure_value':measure_values})

# plot as boxplots
g = sns.catplot(x='model_number',
                y='measure_value',
                hue='measure_name',
                kind='box',
                data=plot_df)

为您提供:

boxplots

使用model_titles = ['Paramater Combination: XY','Parameter Combination: YZ'],我希望我的情节看起来像这样:

'boxplots_legends

0 个答案:

没有答案