# Data Visualization — Line Plot

Learn the basics of data visualization using line plots

Benjamin O. Tayo is a data science educator, tutor, coach, mentor, and consultant. Contact me for more information about our services and pricing: benjaminobi@gmail.com

Dr. Tayo has written close to 300 articles and tutorials in data science for educating the general public. Support Dr. Tayo’s educational mission using the links below:

CashApp: https://cash.app/\$BenjaminTayo

# INTRODUCTION

• Define a line plot
• Generate a line plot using python
• Fit a simple linear regression model and visualize the result using a line plot

Learn about data visualization using scatter plots by clicking on the link below:

A line plot is used in data science to quantify the functional relationship between the independent variable x and the dependent variable y. Using simple linear regression, the relation between x and y can be expressed as y = a + b x, where a and b are the regression coefficients to be determined.

# Python Implementation of a Line Plot

As an illustration, we will fit a simple linear regression model and then visualize the result using a line graph.

## Example 1: Tesla stock price vs. Apple stock price

`# import necessary librariesimport numpy as npimport pandas as pdimport matplotlib.pyplot as pltimport seaborn as sns# obtain datasetdata = pd.read_csv('https://raw.githubusercontent.com/bot13956/datasets/master/tech-stocks-04-2021.csv')# Example 1: Tesla stock price vs Apply stock price# define x and yx = data.AAPL.values[0:11]y = data.TSLA.values[0:11]# fit simple linear…`