python - 带有 y 变量名称的图例,不仅是处理
问题描述
我正在用 python 中的 sns 做一个 2-y 轴图。我得到一个图例,报告我的数据集中的两种治疗方法,但我没有得到图例中 y 标签的名称。先感谢您。
数据框的例子是:
Obs / sampling time /replicate / y1 / y2
1 midday 1 8 9
2 midday 1 8.5 9.5
1 evening 2 4 5
2 evening 2 4.5 5
这就是我的代码的样子:
sns.lineplot(x="Obs", y="y1",
hue="sampling time", style="sampling time", ci=95, markers=True, color="red",
dashes=False, legend="full", label = "y1", data=df)
ax.set_xlabel('time (min)', fontsize=14)
ax.set_ylabel('y1', fontsize=14, color="red")
ax2 = ax.twinx()
sns.lineplot(x="Obs", y="y2", hue="sampling time", style="sampling time", color="blue", markers=True,
legend ="full", ci=95, labels= "Ci", data=df)
ax2.set_ylabel('y2', fontsize=14, color="blue")
ax.get_legend_handles_labels()
ax2.get_legend_handles_labels()
plt.show()
解决方案
推荐阅读
- azure-log-analytics - Azure Log Analytics - 扩展属性
- xamarin - 带有 Visual Studio 社区的 Mac OS 上的 XF iOS 项目 - XAML 热重载已禁用,因为您的 iOS 链接器设置…是不受支持的消息
- mysql - SQL:为 ID 高于先前且满足条件的条目选择不同的计数
- c# - ProjectLombok 的 C# 替代方案 - “不可变设置器”
- c++ - 在类之间传递函数指针作为参数
- firebase - Firebase 项目在本地工作,但部署的版本输出 CORS 错误
- firebase - 使用 cloud_firestore 和 firebase_core 解决 Flutter 版本失败
- python - 从本地读取 plotly-latest.min.js
- javascript - 数组删除最后一个元素而不是删除的一个反应 useState
- laravel - 在单个路由中使用名称属性设置 Throttle 属性