Matplotlib Scatter Plot – Tutorial and Examples

python_tutorials

Introduction

Matplotlib is one of the most widely used data visualization libraries in Python. From simple to complex visualizations, it’s the go-to library for most.

In this tutorial, we’ll take a look at how to plot a scatter plot in Matplotlib.

Import Data

We’ll be using the Ames Housing dataset and visualizing correlations between features from it.

Let’s import Pandas and load in the dataset:

import pandas as pd

df = pd.read_csv('AmesHousing.csv')

Plot a Scatter Plot in Matplotlib

Now, with the dataset loaded, let’s import Matplotlib, decide on the features we want to visualize, and construct a scatter plot:

import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv('AmesHousing.csv')

fig, ax = plt.subplots(figsize=(10, 6))
ax.scatter(x = df['Gr Liv Area'], y = df['SalePrice'])
plt.xlabel("Living Area Above Ground")
plt.ylabel("House Price")

plt.show()

Here, we’ve created a plot, using the PyPlot

 

 

To finish reading, please visit source site