简体   繁体   English

Python Seaborn 线图

[英]Python Seaborn Lineplot

I am new to Python and have a question regarding a lineplot.我是 Python 新手,有一个关于线图的问题。

I have a data set which I would like to display as a Seaborn lineplot.我有一个数据集,我想将其显示为 Seaborn 线图。 In this dataset I have 3 categories which should be on the Y axis.在这个数据集中,我有 3 个类别,它们应该在 Y 轴上。 I have no data for an X axis, but I want to use the index.我没有 X 轴的数据,但我想使用索引。

Unfortunately I did not get it right.不幸的是我没有做对。 I would like to use it like the Excel picture.我想像Excel图片一样使用它。

The columns are also of different lengths.柱子也有不同的长度。

在此处输入图片说明

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

How do I do that?我怎么做?

I appreciate your help.我感谢您的帮助。

First melt your columns and then use hue parameter to plot each line:首先融化你的列,然后使用色调参数来绘制每条线:

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'
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM