In this Matplotlib article we are going to talk about Python Matplotlib Scatter Plot, so when it comes to visualizing the relationship between two numerical variables, scatter plots are an excellent choice.
First of all we need to install Python Matplotlib
1 |
pip install matplotlib |
For creating scatter plots, we need to import the necessary libraries. In this case, we will import Matplotlib pyplot module, which provides a simple and easy interface for creating different types of plots.
1 |
import matplotlib.pyplot as plt |
To illustrate scatter plotting, let’s consider a hypothetical example where we have two variables, x and y. We can represent this data using two lists.
1 2 |
x = [1, 2, 3, 4, 5] y = [10, 15, 12, 17, 20] |
With the data ready, we can now create the scatter plot using the plt.scatter() function. This function requires two parameters, the x-values and the y-values.
1 |
plt.scatter(x, y) |
Matplotlib provides different customization options to enhance the appearance of our scatter plot. We can add labels, titles, gridlines, adjust marker size, color and many more.
1 2 3 4 |
plt.title("Relationship between X and Y") plt.xlabel("X") plt.ylabel("Y") plt.grid(True) |
After that we have customized our scatter plot, we can choose to either display it or save it as an image. To display the plot, use the plt.show() function.
1 |
plt.show() |
If you wish to save the scatter plot as an image, you can use the plt.savefig() function instead.
1 |
plt.savefig("scatter_plot.png") |
Run the complete code and this is the output

Learn More on Python Matplotlib
- How to Create BarChart with Matplotlib
- How to Create PieChart in Matplotlib
- Python Matplotlib Line Plot