0

I want to plot the same pixel across multiple frames onto a 3d scatter plot - I have managed to get the plot working however I want the colour of each point to be the colour its values represent.

I have tried building an array of all the rgb values and passing it into the colors parameter. I have also tried passing in the corresponding rgb values directly.

#Data visualisation
from matplotlib import pyplot
from mpl_toolkits.mplot3d import Axes3D

fig = pyplot.figure()
ax = Axes3D(fig)

B_vals = []
G_vals = []
R_vals = []
rgb_array = []

x_pix = 1
y_pix = 1

for i in range(len(img_list)):

    blue = img_list[i][x_pix][y_pix][0]
    green = img_list[i][x_pix][y_pix][1]
    red = img_list[i][x_pix][y_pix][2]

    B_vals.append(blue)
    G_vals.append(green)
    R_vals.append(red)

    rgb_array.append(list(img_list[i][x_pix][y_pix]))


ax.set_xlim(0, 255)
ax.set_ylim(0, 255)
ax.set_zlim(0, 255)
ax.set_xlabel('Blue')
ax.set_ylabel('Green')
ax.set_zlabel('Red')
ax.scatter(B_vals, G_vals, R_vals, color = (B_vals,G_vals,R_vals))
pyplot.show()

I am currently getting the error:

ValueError: 'color' kwarg must be an mpl color spec or sequence of color specs.
For a sequence of values to be color-mapped, use the 'c' argument instead.
TisButaScratch
  • 163
  • 1
  • 5
  • 17
  • 1
    You need a list of RGB values, not a tuple of 3 single channel values. – ImportanceOfBeingErnest Aug 28 '19 at 19:09
  • Thanks @ImportanceOfBeingErnest I have passed in the rgb_array instead which is a list of rgb values, however then i get the error "'c' argument has 613 elements, which is not acceptable for use with 'x' with size 613, 'y' with size 613." – TisButaScratch Aug 28 '19 at 19:14
  • Ok so i think i have now done what you said, I turned the rgb_array into an array with colours = np.array(rgb_array), and then plotted with ax.scatter(r_vals, g_vals, b_vals, color = colours/255) – TisButaScratch Aug 28 '19 at 19:56

0 Answers0