Like scatter plots, line plots show the relationship between two variables. However, in a line plot we are exploring the continuous pattern of one variable over increments of another. Frequently, the incremental variable is a measurement of time.
We can use
sns.lineplot() with the standard parameters
y to create a line plot with seaborn. Because we want to read the pattern continuously from left to right, we set
x to the incremental variable and
y to the variable of interest. For example, we could use the following code to plot
total_sales over each
month of a year from dataset
sns.lineplot(data=df, x='month', y='sales_totals')
This code will work whether you have one value or multiple values of the continuous variable for each increment.
- When there is only one value per increment, seaborn will plot the line at that value.
- When there are multiple values per increment, seaborn will plot the line at the mean value for that increment.
When plotting means, seaborn will also plot a shaded area around the line that shows the 95% confidence interval at each increment. We can hide these shaded areas by setting the
ci parameter to
Note: For seaborn version >= 0.12.0, the
ci parameter is deprecated in favor of the
errorbar parameter. Set
errorbar=None for later versions of seaborn.
After running the first two code cells, display the first 10 rows of the
plant1data dataset. This dataset contains measurements over time for only one plant.
Create a line plot of
Time using the
plant1data dataset. This plot shows
Lateral_spread over time for Plant 1 only.
Now let’s view the full dataset for five plants. Show the first 10 rows of the
Make a line plot of
Time using the
plants dataset. This plot shows the average
Lateral_spread of all five plants over
Time with a 95% confidence interval given as a shaded region around the line.
Make the same plot of average
Lateral_spread but remove the confidence interval shading.