I am trying to plot two lines on the Y axis with sns.lineplot
with a dataframe that follows this structure:
Datestamp y_1 y_2
2020-08-01 0 1
2020-08-02 1 2
2020-08-03 3 1
2020-08-04 5 1
In the documentation it uses hue
which I do not have in my dataFrame, when I run two lines one below the other like so:
sns.lineplot(x = 'Datestamp', y = 'y_1', data=df)
sns.lineplot(x = 'Datestamp', y = 'y_2', data=df)
And add a random hue
parameter I am not sure if the line hues
are the same for different lines and the hue
legend gets duplicated.
How can I get a simple two-line chart using seaborn?
Given you current structure you can do this:
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
sns.lineplot(x = 'Datestamp', y = 'y_1', data=df, color='r', lw=3)
sns.lineplot(x = 'Datestamp', y = 'y_2', data=df, color='g', lw=3)
plt.legend(labels=['x_1','y_1'], facecolor='white')
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.