I want to get insight for some values. I have two vectors of 300 dimensions, and want to compare them coordinate by coordinate. So I thought to plot each point with a different color, but the color for a dimension to be the same so that I would know which coordinates are lying where.

I have the below code, which I modeled on some results at stackoverflow.

colors = itertools.cycle(["r", "g", "b"])

for d_in in inp_samples:
    clr = next(colors)
    plt.scatter(len(inp_samples), d_in, c=clr)

colors = itertools.cycle(["r", "g", "b"])

for d_out in out_samples:
    clr = next(colors)
    plt.scatter(len(out_samples), d_out, c=clr) 

But the plot I am getting is very weird. I was expecting it would be scattered but it is something like this:

plot of the  two vectors

I also tried this:

colors = cm.jet(np.linspace(0, 1, 300))

for d_in, d_out, c in zip(inp_samples, out_samples, colors):
    plt.scatter(len(inp_samples), d_in, c=c)
    plt.scatter(len(out_samples), d_out, c=c)

enter image description here

Can anyone help in understanding what I am doing wrong?

  • $\begingroup$ What about a line plot where x coordinate is dimension number (1-300) and y is the vectors value. Seems easier to compare to me... $\endgroup$
    – kbrose
    Commented Jun 26, 2018 at 13:49

1 Answer 1


In scatter in Matplotlib, the first two arguments must be the $x$ and $y$ values that you want to combine. In your code, the first value ($x$) is len(inp_samples) (or len(out_samples)) which is the number 300, so all your points line on the $x=300$ vertical line.

In order to combine the inp_samples with the out_samples, I too would recommend using zip, as in your second sample of code. Just replace

plt.scatter(len(inp_samples), d_in, c=c)
plt.scatter(len(out_samples), d_out, c=c)


plt.scatter(d_in, d_out, c=c)

(and see if it works).


So I thought to plot each point with a different color, but the color for a dimension to be same, so that i would know, which dimensional points are lying where.

In a scatter plot, there is no need for any special colouring -- by two values forming one pair of $(x_i,y_i)$, it is already given which point belongs to which.

You could also try to plot $(i,x_i)$ and $(i,y_i)$ in the same plot. In this case, points above each other belong together and you still don't need any special colouring.

colors = itertools.cycle(["r", "g", "b"])
for i in range(300):
    clr = next(colors)
    plt.scatter(i, d_in[i], c=clr)
    plt.scatter(i, d_out[i], c=clr)
  • $\begingroup$ the plot now looks like a linear line. $\endgroup$ Commented Jun 26, 2018 at 7:27
  • $\begingroup$ Maybe your two vectors are in a linear (or affine) relationship?! You could print the first 10 or 20 values of each and inspect the numbers by eye how they relate. $\endgroup$ Commented Jun 26, 2018 at 7:44
  • $\begingroup$ Let me explain about the vectors, the two vectors v_in and v_out, v_in is a the original vector, and v_out is the transformed vector, and on v_out i have done some operation, now I want to know know, by how much distance a dimension of v_in and v_out are far or close to each other. There should be a linear relationship but, I want to see each dimension in space, and not what the relationship is. $\endgroup$ Commented Jun 26, 2018 at 8:51
  • $\begingroup$ Then perhaps try your 2nd code with my suggestion and a new colormap, e.g. 'BrBG' or a sequential one: matplotlib.org/gallery/color/colormap_reference.html You could also try plotting the difference: plt.plot(np.linspace(0, 1, 300), np.subtract(v_out, v_in), 'bx'). $\endgroup$ Commented Jun 26, 2018 at 9:20
  • $\begingroup$ It worked pretty well. $\endgroup$ Commented Jun 26, 2018 at 10:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.