Scatter plots are commonly used to plot data for one or more classes. Moreover, it is used to classify and view the behavior of the data. It can be plotted by using scatter() function of the matplotlib module.

The syntax for plotting a scatterplot in Python is:

matplotlib.pyplot.scatter(xys=Nonec=Nonemarker=Nonecmap=Nonenorm=Nonevmin=Nonevmax=Nonealpha=Nonelinewidths=Noneverts=Noneedgecolors=None*plotnonfinite=Falsedata=None**kwargs)[source] 

A simple example of a scatter plot in Python is given below.

import matplotlib.pyplot as plt

marks_boys = [30, 29, 49, 48, 100, 48, 38, 45, 20, 30]
marks_girls = [89, 90, 70, 89, 100, 80, 90, 100, 80, 34]
marks_range = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]

# Setting the figure size
plt.figure(figsize=(10, 8))

# Plotting the scatter plot
plt.scatter(marks_range, marks_boys, color='b')
plt.scatter(marks_range, marks_girls, color='r', )

# Setting title and labels
plt.title('Sample scatter plot')
plt.xlabel('Marks Range')
plt.ylabel('Marks Obtained')

# Setting the legend
plt.legend(('Boys', 'Girls'))

# Displaying the plot
plt.show()
Scatter plot in Python

In Conclusion

Scatter plots are popularly used for visualization of data in Python. You may like this tutorial on other kinds of plots in Python: Data Visualization in Python (With Tutorials).

LEAVE A REPLY

Please enter your comment!
Please enter your name here