Introduction

In this tutorial, we want to create a Scatterplot. In order to do this, we use the scatter() function of Matplotlib.

Import Libraries

First, we import the Pyplot submodule. The Pyplot submodule contains a collection of important functions such as the plot() function or the scatter() function. In addition, we import NumPy.

import matplotlib.pyplot as plt
import numpy as np

Define Data

Now, let's define some example data points. In order to do this, we create the following NumPy Arrays:

x = np.array([1, 2, 3, 4, 5])
y = np.array([4, 6, 10, 12, 18])

Scatter Plot

Now, we want to plot these data points. In order to generate a Scatter Plot, we can use the scatter() function. Another way to generate a Scatter Plot is to use the plot() function. But in this post we consider the scatter() function. We use the scatter() function just by default, without any further configurations.

plt.scatter(x,y)
plt.show()

Change Style

Let's define some specific configurations such as the marker type, the edgecolor or the labels of the axes.

plt.scatter(x, y, color="green", marker = "s", edgecolors = "yellow")
plt.xlabel("X values")
plt.ylabel("Y values")
plt.show()

Conclusion

Congratulations! Now you are one step closer to become an AI Expert. You have seen that it is very easy to create a Scatterplot. We can simply use the scatterplot() function of Matplotlib. Try it yourself!

Instagram

Also check out our Instagram page. We appreciate your like or comment. Feel free to share this post with your friends.