1
votes

I have 100 data points and a time series at each data points.I calculated the distance (dist in code) between every pair of points and the correlation coefficient (corr in code) between the corresponding time series. Now I need to have a scatter plot of distance (in the x axis) v/s correlation coefficient (in the y axis) and the marker color should give the no. of occurrences of the correlation coefficient at each distance value. I tried the following code using matplotlib

colors=np.random.randint(len(dist))
cmap=plt.cm.viridis
plt.scatter(dist,corr,c=colors,cmap=cmap)
plt.colorbar()
plt.show()

The result was incorrect.

Is it possible to get the desired result using scatter plot? Or, is there any other way of getting it?

1

1 Answers

1
votes

You are trying to generate a color map with a single number as color differentiator, i.e. len(colors) = 1, but you need len(colors) = len(dist).

Try:

colors=np.random.randint(len(dist), size=len(dist))

Not sure what you want to achieve. Perhaps this would work instead:

plt.scatter(dist,corr,c=dist,cmap=cmap)