python - RGB cube of an image -


i'm trying create rgb cube of image matplotlib in python. have python list rgb of pixels in format [(2,152,255),(0,0,0)...]. plot points scatter function, don't know how plot each rgb point it's respective rgb colour.

i've tried doing ax.scatter(paleta[0],paleta[1],paleta[2],c = rgblist), function expect rgba value...

i expect somthig this:

enter image description here

code :

paleta=zip(*rgblist) fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.scatter(paleta[0],paleta[1],paleta[2]) ax.grid(false) ax.set_title('grid on') plt.savefig('images\\rgbcube.png')

try scaling rgb values range [0,1]:

ax.scatter(paleta[0],paleta[1],paleta[2], c=[(r[0] / 255., r[1] / 255., r[2] / 255.) r in rgblist])

this works in following example:

import random import matplotlib.pyplot plt mpl_toolkits.mplot3d import axes3d, axes3d  rgblist = [(random.randint(0,255), random.randint(0,255), random.randint(0,255)) in range(100)] paleta=zip(*rgblist) fig = plt.figure() ax = axes3d(fig) ax.scatter(paleta[0],paleta[1],paleta[2], c=[(r[0] / 255., r[1] / 255., r[2] / 255.) r in rgblist]) ax.grid(false) ax.set_title('grid on') plt.savefig('blah.png') 

giving output:

enter image description here


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -