简体   繁体   中英

Python Seaborn Lineplot

I am new to Python and have a question regarding a lineplot.

I have a data set which I would like to display as a Seaborn lineplot. In this dataset I have 3 categories which should be on the Y axis. I have no data for an X axis, but I want to use the index.

Unfortunately I did not get it right. I would like to use it like the Excel picture.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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