Note

Go to the endto download the full example code.

3D voxel / volumetric plot with RGB colors#

Demonstrates usingAxes3D.voxels to visualize parts of a color space.

importmatplotlib.pyplotaspltimportnumpyasnpdefmidpoints(x):sl=()for_inrange(x.ndim):x=(x[sl+np.index_exp[:-1]]+x[sl+np.index_exp[1:]])/2.0sl+=np.index_exp[:]returnx# prepare some coordinates, and attach rgb values to eachr,g,b=np.indices((17,17,17))/16.0rc=midpoints(r)gc=midpoints(g)bc=midpoints(b)# define a sphere about [0.5, 0.5, 0.5]sphere=(rc-0.5)**2+(gc-0.5)**2+(bc-0.5)**2<0.5**2# combine the color componentscolors=np.zeros(sphere.shape+(3,))colors[...,0]=rccolors[...,1]=gccolors[...,2]=bc# and plot everythingax=plt.figure().add_subplot(projection='3d')ax.voxels(r,g,b,sphere,facecolors=colors,edgecolors=np.clip(2*colors-0.5,0,1),# brighterlinewidth=0.5)ax.set(xlabel='r',ylabel='g',zlabel='b')ax.set_aspect('equal')plt.show()
voxels rgb

Tags:plot-type: 3Dstyling: color

Total running time of the script: (0 minutes 2.341 seconds)

Gallery generated by Sphinx-Gallery