Index colour in matplotlib Tri-surface plot

495 views Asked by At

I have created a tri-surface plot from a set of x, y and z co-ordinates

I want to index the colour of the plot to a set of values, calculated per-vertex.

The problem is not in mapping these values to colour values, but rather, in assigning the colour values to the faces in a sensible way.

In the code below you can see that I have x,y,z co-ordinates for four vertices in verts. And I have one value for each vertex in "vals", which are mapped to RGB values in colours.

I want to assign each face the average colour of the three vertices that define it. I am actualy trying to do this on a much more complex polygon and need to be able to determine programmatically, which "colours" values to average in order to assign it to the face in question. (i.e. which vertices define which face)

or if you can think of a simpler way to get the face colour indexed to the values at adjacent vertices that would be great

import matplotlib.pyplot as plt
import matplotlib.cm as cm
from mpl_toolkits.mplot3d import Axes3D
from numpy import array
verts = array(([1,2,3],[4,5,7],[-1,6,9],[6,7,2])) # X,Y,Z co-ordinates for 4 vertices

vals = array([0.1,0.3,0.5,0.7]) # values calculated for each verex


#map vals to RGB
sm = cm.ScalarMappable()
sm.set_clim(vmin=0,vmax=1)
sm.set_cmap('jet')
colours = sm.to_rgba(vals)

ax = plt.figure().add_subplot(111, projection='3d')

ax.plot_trisurf(verts[:,0],verts[:,1],verts[:,2])
plt.show()
0

There are 0 answers