The easiest way to do this is to set a low alpha
, and then when the points plot on top of each other they look darker.
import numpy as np
import matplotlib.pyplot as plt
data = [i for i in range(8) for j in range(np.random.randint(10))]
x, y = np.array(data), np.array(data)
plt.scatter(x, y, alpha=.1, s=400)
plt.show()
Of course, you can also change the size of the point or the color directly. To do this, you need to find the number of overlapping points and then set the size (using the s
scatter plot parameter) or the color (using c
) or both. (But setting alpha is easiest since it doesn't require explicitly counting the overlaps.)