Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

python - How to draw multiple lines with Seaborn?

I am trying to draw a plot with two lines. Both with different colors. And different labels. This is what I have come up with.

enter image description here

This is code that I have written.

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

data1 = pd.read_csv("/content/drive/MyDrive/Summer-2020/URMC/training_x_total_data_ones.csv", header=None)
data2 = pd.read_csv("/content/drive/MyDrive/Summer-2020/URMC/training_x_total_data_zeroes.csv", header=None)

sns.lineplot(data=data1, color="red")
sns.lineplot(data=data2)

What am I doing wrong?

Edit

This is how my dataset looks like

enter image description here

question from:https://stackoverflow.com/questions/65835962/how-to-draw-multiple-lines-with-seaborn

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Try specifying the x and y of the call to sns.lineplot?

import pandas as pd
import numpy as np
import seaborn as sns

x = np.arange(10)

df1 = pd.DataFrame({'x':x,
                    'y':np.sin(x)})

df2 = pd.DataFrame({'x':x,
                    'y':x**2})

sns.lineplot(data=df1, x='x', y='y', color="red")
sns.lineplot(data=df2, x='x', y='y')

enter image description here

Without doing so, I get a similar plot as yours.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...