python - 多种线型的 Seaborn Lineplot 限制的替代方案?
问题描述
我有一些纵向测试数据,我想检查这些数据的总体趋势。我的数据是这样设置的:
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 的 lineplot样式参数似乎被限制为 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()
那么有没有办法绕过线图的这个限制,还是我必须通过 Matplotlib 来完成这个?如果是后者,Matplotlib 代码会是什么样子?
另外,有没有办法在 seaborn 图上生成图例,显示每个捐赠者的性别,而不是每个特定的捐赠者?
解决方案
推荐阅读
- excel - 状态栏消息文本的 IF 条件有什么问题
- python-2.7 - flake8 在 vscode 中没有显示致命错误
- asp.net-core - 如何在 Autofac 多租户中使用 IHttpContextAccessor?
- javascript - 表单验证失败后如何显示模式?
- javascript - 对 javascript 对象的引用显然在不同的地方返回不同的值,中间没有修改
- java - 同一类的多个实例从事件总线获取相同的事件
- android - Android在滑动时实现文本完成
- html - 如何为孩子的每个孩子设置不同的背景颜色
- node.js - 动态重置 Express 静态目录
- java - 解析计算器的逆表达式