Matplotlib scatter list of points

Active April 05, 2019 / Viewed 60232 / Comments 0 / Edit

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

Matplotlib scatter list of points
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:

Matplotlib scatter list of points
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()

Another solution is to combine multiple scatter plots:

Matplotlib scatter list of points
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