我有一些纵向测试数据,我想检查这些数据的总体趋势。我的数据设置如下:
import seaborn as sns
import matplotlib.pyplot as plt
test_data = pd.read_csv('./Files Used to Generate Graphs/test_data.csv',header = 0)
test_data
我要绘制此数据的方式是让每个供体都有他/她自己的纵向数据线,但是要根据供体的性别为每条线上色,如下所示:
test_plt = sns.lineplot(x = 'Timepoint',y = 'Prevalence',
hue = 'Gender',
data = test_data,
style = 'Donor',
palette = dict(Male = 'red',
Female = 'blue'))
for line in test_plt.lines:
line.set_linestyle("-")
ax = plt.gca()
legend = ax.legend()
legend.set_visible(False)
plt.figure()
但是,似乎seaborn的线图的 style 参数限制为6种类型。如果我尝试在数据中添加另一个供体并将其绘制出来,则会得到以下信息:
append_df = pd.DataFrame(index = [12,13],
columns = ['Donor','Timepoint','Gender','Prevalence'])
append_df['Donor'] = 7
append_df['Gender'] = 'Female'
append_df.loc[12,'Timepoint'] = 1945
append_df.loc[13,'Timepoint'] = 1948
append_df.loc[12,'Prevalence'] = 18
append_df.loc[13,'Prevalence'] = 36
test_data = test_data.append(append_df)
test_data
test_plt = sns.lineplot(x = 'Timepoint',y = 'Prevalence',
hue = 'Gender',
data = test_data,
style = 'Donor',
palette = dict(Male = 'red',
Female = 'blue'))
for line in test_plt.lines:
line.set_linestyle("-")
ax = plt.gca()
legend = ax.legend()
legend.set_visible(False)
plt.figure()
那么有什么方法可以绕过 lineplot 上的此限制,或者我必须为此通过Matplotlib吗?如果是后者,那么Matplotlib代码会是什么样子?
单独说明一下,是否可以在海图上生成图例,以显示每个供体的性别,而不是每个特定供体的性别?