x = np.linspace(0, 20, 100)
y = np.sin(x)
z = x + 20 * y
scaled_z = (z - z.min()) / z.ptp()
colors = plt.cm.coolwarm(scaled_z)
plt.scatter(x, y, marker='+', edgecolors=colors, s=150, linewidths=4)
plt.show()
matplotlib scatter plot colour as function of third variable