How to specify colors in matplotlib.pyplot.trisurf

I am trying to build a shell using trisurf. I need to specify the color of each triangle (there are a lot of them). It can be done? I tried this, but it does not work:

import matplotlib.pyplot as plt: ... fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot_trisurf(points[:,0], points[:,1], points[:,2], triangles=faces, cmap=facecolors) plt.show() 

facecolors - matrix with len(faces) rows; each row (R, G, B). If I omit the cmap argument, it certainly looks normal, but monochromatic.

Can I do what I want?

-1
source share
1 answer

As for colors, you will need to decide

  • do you want to use data ( points[:,2] ) in combination with a color palette to colorize your surface or if
  • you want to specify the colors yourself.

In the first case, cmap should be a matplotlib colormap, not an array. You can use a named set of colors, such as "jet" , or create your own flower card.

In the second case, you need to omit the cmap keyword and use the facecolors keyword argument facecolors , which will be passed to the Poly3DCollection in the background. Strike> The facecolor argument is currently ignored. In the code, you can see that although the facecolor argument facecolor correctly passed to the Poly3DCollection , facecolor is then overwritten with color , which does not seem to accept the numpy array.

0
source

All Articles