From Python beginner to making linear regression graphs

Christopher Collins
3 min readAug 6, 2022

Matplotlib is a Python library that can be used for creating 2D plots.

Beginners can create a basic plot using matplotlib.pyplot.

This library is typically imported as follows:

import matplotlib.pyplot as plt 

Once imported, beginners can create a basic plot using the following code:

plt.plot([1,2,3,4])
plt.show()

This will create a basic plot with the x-axis values 1, 2, 3, and 4.

The y-axis values will be automatically generated.

Full code

import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.show()

Result

To add labels to the x- and y-axes, use the following code:

plt.xlabel(‘x-axis label’)
plt.ylabel(‘y-axis label’)

Full code


import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.xlabel('x-axis label')
plt.ylabel('y-axis label')
plt.show()

Result

Doing Linear Regression with Matplotlib

Linear regression is a statistical method used to predict a continuous dependent variable from a set of independent variables. It is the simplest form of regression and is used to model linear relationships between variables.

The matplotlib Python library can be used to create scatter plots, which are useful for visualizing linear relationships between variables. To create a scatter plot, you need to have two sets of data: one for the independent variable and one for the dependent variable. The independent variable is plotted on the x-axis and the dependent variable is plotted on the y-axis.

To fit a linear regression model, you need to find the line of best fit. This is the line that minimizes the sum of…

Christopher Collins

I write about coding, crypto, the tech future,please follow my publication https://medium.com/aiwriters/ 😀