python - Python Seaborn 线图
问题描述
我是 Python 新手,对线图有疑问。
我有一个数据集,我想将其显示为 Seaborn 线图。在这个数据集中,我有 3 个类别,它们应该在 Y 轴上。我没有 X 轴的数据,但我想使用索引。
不幸的是,我没有做对。我想像 Excel 图片一样使用它。
列的长度也不同。
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv("Testdata.csv", delimiter= ";")
df
Double Single Triple
0 50.579652 24.498143 60.954680
1 53.313919 24.497490 60.494626
2 54.174343 24.490651 60.052566
3 56.622435 24.485605 59.622501
4 59.656155 26.201791 59.199581
... ... ... ...
410 NaN NaN 75.478118
411 NaN NaN 73.780804
412 NaN NaN 72.716096
413 NaN NaN 72.468472
414 NaN NaN 71.179819
我怎么做?
我感谢您的帮助。
解决方案
首先融化你的列,然后使用色调参数绘制每一行:
fig, ax = pyplot.subplots(figsize=(10, 10))
ax =seaborn.lineplot(
data= df.melt(id_vars='index').rename(columns=str.title),
x= 'index',
y= 'value',
hue='varaible'
)
推荐阅读
- typescript - 如何从本地目录而不是全局目录运行 TypeScript
- html - 当用户点击从春季发送给他的链接时,如何创建电子邮件验证页面?
- sql - 在 READ_COMMITTED_SNAPSHOT ON 的情况下删除然后插入 SQL Server 时出现问题
- android - Android bottomRightRadius +海拔导致灰色条
- python-2.7 - 带有子进程的多个壳管如何工作?
- dji-sdk - 由于缺少所需的架构 armv7,无法构建 DJI 示例应用程序
- https - 使用 HTTPS 时 Jmeter 5 上的连接重置
- c - 任何人都可以举一个例子说明这个优先级很重要吗?
- python - Keras:可重现的结果 CPU 上的简单 MLP
- python - 如何在scrapy中设置优先级