我正在使用seaborn.catplot
绘制数据。我想在我的主要x轴下方添加第二个x轴,以描述另一个参数。我的主要x轴由plot_df['first_param']
的值定义,我想在其下方绘制plot_df['second_param']
的值。
这是我的代码:
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()
first_param = np.repeat([0.8,0.7],40)
second_param = np.repeat(['99%','80%'],40)
folds=np.tile([1,2,3,4,5,6,7,8,9,10],8)
plot_df = pd.DataFrame({'model_number':model_numbers,
'measure_name':measure_names,
'measure_value':measure_values,
'first_param':first_param,
'second_param':second_param,
'outer_fold':folds})
# add a column to separate between test scores and train scores
train_scores = ['Train BAC','Train SPEC']
plot_df['score_type'] = np.where(plot_df['measure_name'].isin(train_scores),'train_score','test_score')
# plot as boxplots
g = sns.catplot(x='first_param',
y='measure_value',
col='score_type',
hue='measure_name',
kind='box',
data=plot_df)
产生:
我想看一下我的情节:
请注意,这篇文章与to this post密切相关,但是在我的情况下,有必要对Seaface FacetGrid对象而不是matplotlib图形对象进行处理。