1

I need to color half of an array one color.

Suppose I have 2 arrays that I concatenate

arr1 = [[1,2,
         3,4]]
arr2 = [[1,2,
         3,4]]

arr 3 =  np.concatenate((arr1, arr2), axis=0)

plt.scatter(arr3[:,0], arr3[:,1], c= ???)

This is an example, my real data set has 16,000 data points so a separate label array might not be possible. From index 0 - 8000~ I want to be red. 8000 - 16000 I want to be blue. Thanks

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
  • split it in to two array, and plot twice on the same plot using something like `plt.plot(X,y,'o',c='red')` – Mohammad Athar Aug 30 '18 at 16:58
  • Splitting the array is not possible in my real world problem, needs to be concatenated – Tristan Lassiter Aug 30 '18 at 17:02
  • Just find the middle index (halfway) as `mid = int(len(arr3[0])/2)` and then use something like `plt.scatter(arr3[:,0][0:mid], arr3[:,1][0:mid], c= 'r')` and `plt.scatter(arr3[:,0][mid:], arr3[:,1][mid:], c= 'b')`. – Sheldore Aug 30 '18 at 17:04
  • instead of splitting it, can you plot a subset? like `plt.scatter(x[0:100], y[0:100], 'o', 'red')` – Mohammad Athar Aug 30 '18 at 17:37
  • There is no reason why splitting the array would not be possible in just *any* real world case (but if you think there is, that would be an [xyproblem](http://xyproblem.info)). There is of course the academic solution of using a colormap, consisting of blue and red and supplying a newly created array, which consists of different values for the first 8000 values than for the last 8000, to the `c` argument. – ImportanceOfBeingErnest Aug 30 '18 at 19:21

1 Answers1

2

A simple example on how to do that, supossing you have an array of 16,000 elements and two dimensions. You can plot separately the two sets of points in the same figure, as follows:

plt.scatter(arr3[0:8000, 0], arr3[0:8000, 1], c="red")
plt.scatter(arr3[8000:16000, 0],arr3[8000:16000, 1], c="blue")

plt.show()

The two sets of points will show in the same graph with different colors. You just have to modify the indexes so they fit your data.

Ziessel
  • 57
  • 9
  • this is what I proposed, but the comments indicate that splititng the array is not possible, for some reason – Mohammad Athar Aug 30 '18 at 17:27
  • @MohammadAthar But in both our solutions the array is not literally 'splitted', the array keeps concatenated, the split is just done through indexing. I can't think of any scenario where there would be a reason for not being able to index a matrix like this... – Ziessel Aug 31 '18 at 16:25