I am plotting data with matplotlib, I have obtained a scatter plot from two numpy arrays:
ax1.scatter(p_100,tgw_e100,color='m',s=10,label="time 0")
I would like to add information about the eccentricity of each point.
For this purpose I have a third array of the same length of p_100 and tgw_e100, ecc_100 whose items range from 0 to 1.
So I would like to set the transparency of my points using data from ecc_100 creating some sort of shade scale.
I have tried this:
ax1.scatter(p_100,tgw_e100,color='m',alpha = ecc_100,s=10,label="time 0")
But I got this error:
ValueError: setting an array element with a sequence.
According to the documentation alpha can only be a scalar value.
Thus I can't see any other way than looping over all your point one by one.
for x, y, a in zip(p_100, tgw_e100, ecc_100):
ax1.scatter(x, y, color='m',alpha = a, s=10)
I think the labelling will be quite weird though, so you might have to create the legend by hand. I omitted that from my solution.
I guess a patch to make the alpha keyword argument behave like c and s would be welcome.
Update May 6 2015
According to this issue, changing alpha to accept an array is not going to happen. The bug report suggests to set the colors via an RGBA array to control the alpha value. Which sounds better than my suggestion to plot each point by itself.
c = np.asarray([(0, 0, 1, a) for a in alpha])
scatter(x, y, color=c, edgecolors=c)
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