1 | initial version |
import matplotlib.pyplot as plt
from matplotlib import cm
from mpl_scatter_density import ScatterDensity
x = [1, 2, 3, 4, 5]
y = [1, 1, 2, 2, 2]
density = [5, 10, 20, 30, 40]
fig, ax = plt.subplots()
sc = ScatterDensity(ax, x, y, density)
cmap = cm.get_cmap('jet', 30) #create a color map using the 'jet' color scheme with 30 different colors
sizes = [20, 40, 60, 80, 100] #a list of five different dot sizes to correspond with the five different density values
sc.scatter(s=100, marker='.', cmap=cmap, sizes=sizes, lw=0)
The sizes
argument in sc.scatter()
specifies the different dot sizes to be used for the different density levels. The s=100
argument sets the default size for the dots in the plot. Adjust the sizes
argument and the s
argument as needed to achieve the desired dot size.