Data Visualization — Line Plot
--
Learn the basics of data visualization using line plots
About the Author
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:
PayPal: https://www.paypal.me/BenjaminTayo
CashApp: https://cash.app/$BenjaminTayo
INTRODUCTION
After reading this article, the reader will learn the following:
- 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 libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
# obtain dataset
data = 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 y
x = data.AAPL.values[0:11]
y = data.TSLA.values[0:11]
# fit simple linear…