A Python scatter plot example can be used as a reference to build another plot, or to remind us about the proper syntax.
Python scatter plots example often use the Matplotlib library because it is arguably the most powerful Python library for data visualization. It is usually used in combination with the Python Numpy library.
Suppose you have two Python lists. One is a list of home prices, and the other list represents the size of the living area. You want to use these lists to see if there is a correlation between the two. This problem calls for a simple linear regression analysis. However, a scatter plot can help infer if there is a strong or weak correlation.
The Python Scatter Plot Example
The list for home prices is:
The list for living area size is:
The next step is to import the libraries.
import pandas as pd
import matplotlib.pyplot as plt
Inline comments can explain the remaining steps.
np_homeprice = np.array(homeprice)
np_livearea = np.array(livearea)
# Set arguments for the x and y axis
# Label x and y axis
plt.xlabel(‘Living Area Square Footage’)
plt.ylabel(‘Sale Price of Home’)
# Give title to plot
plt.title(‘Home Sale Price vs. Size of Living Area’)
# Display the plot
Executing this code will result in a scatter plot.