Data Visualization with Line Plots
Learn how to design and interpret line plots as well as bootstrapping techniques used in seaborn library plots.
We'll cover the following...
Overview
Line plots represent continuous relationships between two variables, where time is often one of the variables used and is plotted on the x-axis. Line plots are mainly used for time series data analysis, where we observe the trends and patterns of how a variable changes over time.
Use line plots in Seaborn
We begin by importing the required libraries (seaborn, matplotlib, and pandas) and set the default seaborn styling theme using the sns.set_theme() function. Next, we import the fmri dataset using the sns.load_dataset() function and view the first five records using the pandas head() method. The dataset has five columns—the column timepoint represents the time.
Let’s plot a line plot for timepoint and signal. We use the sns.lineplot() function and pass fmri_df in the data parameter, timepoint on the x-axis and signal on the y-axis. We can also customize the plot with the matplotlib axis object plt to set the title, xlabel, and ylabel. We save the figure using plt.savefig(). The resulting line plot is shown below:
The plot shows that the signal value peaked at timepoint 5.0 and slowly decreased.
We can further customize the plot by passing the event column to the hue parameter and adding the error bars by setting err_style='bars' in the sns.lineplot() function. The resulting plot is shown below:
Let’s now demonstrate line plots on another dataset named IrishWhiskeySales.csv. This Irish Whiskey Sales dataset is publicly available online.
We import the dataset in the pandas DataFrame sales_df. We ...