I have some data that looks like this: (4,120,507.0),(6, 37, 7012.0),etc
The first two is the coordinates, another is the values. I've drawn a scatter plot based on these coordinates.
So how can I color these points based on the values? the bigger the values is ,the darker the color? Thanks a lot
In a scatter plot, the c argument to plt.scatter(x,y,c=z) can be set to determine the color depending on the value of z. The color is set according to a colormap, which can be set with the cmap argument.
import matplotlib.pyplot as plt
a = [(4,120,507.0),(5, 80, 5415.0),(6, 37, 7012.0),(7, 96, 2173.0),(8,57,3777.0)]
x,y,z = zip(*a)
plt.scatter(x,y, c=z, s=100, cmap="YlOrBr", edgecolor="k")
plt.colorbar(label="values")
plt.show()

Also refer to the documentation and look at the matplotlib examples.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With