How to increase the size of scatter points in matplotlib ?

Published: April 05, 2019

DMCA.com Protection Status

Examples of how to increase the size of scatter points in matplotlib:

Increase the size of all points

To increase the size of scatter points, a solution is to use the option "s" from the function scatter(), example

How to increase the size of scatter points in matplotlib ?
How to increase the size of scatter points in matplotlib ?

import matplotlib.pyplot as plt

x = [1,2,3,4,5,6,7,8]
y = [4,1,3,6,1,3,5,2]

plt.scatter(x,y,s=400,c='lightblue')

plt.title('Nuage de points avec Matplotlib')
plt.xlabel('x')
plt.ylabel('y')
plt.savefig('ScatterPlot_07.png')
plt.show()

Points with different size

To plot points with different size, a solution is to provide a list of size (or an array) to "s". Note that the list must be of the same size that the input data:

How to increase the size of scatter points in matplotlib ?
How to increase the size of scatter points in matplotlib ?

import matplotlib.pyplot as plt

x = [1,2,3,4,5,6,7,8]
y = [4,1,3,6,1,3,5,2]
size = [100,500,100,500,100,500,100,500]

plt.scatter(x,y,s=size)

plt.title('Nuage de points avec Matplotlib')
plt.xlabel('x')
plt.ylabel('y')
plt.savefig('ScatterPlot_06.png')
plt.show()

Combining several scatter plots

Another solution is to combine multiple scatter plots:

How to increase the size of scatter points in matplotlib ?
How to increase the size of scatter points in matplotlib ?

import matplotlib.pyplot as plt

x = [1,2,3,4]
y = [4,1,3,6]

plt.scatter(x, y, s=100, c='coral')

x = [5,6,7,8]
y = [1,3,5,2]
size = [100,500,100,500]

plt.scatter(x, y, s=500, c='lightblue')

plt.title('Nuage de points avec Matplotlib')
plt.xlabel('x')
plt.ylabel('y')
plt.savefig('ScatterPlot_08.png')
plt.show()

References

Links Site
matplotlib.pyplot.scatter Matplotlib doc
pyplot scatter plot marker size stackoverflow
Image

of