I am working on a visualization problem where I want to plot a geometrical part using polygons specified by their node coordinates (I have basically been importing the polygon coordinates from a FEM Program). Now I am struggling with changing the facecolor of each polygon without replotting everytime (takes a lot of time). Here is what I've coded:
fig = plt.figure()
ax = axes3d.Axes3D(fig)
for i in range(0, len(e_coordinates)):
if len(e_coordinates[i]) == 3:
poly = p3dc([[e_coordinates[i][0], e_coordinates[i][1], e_coordinates[i][2]]],
facecolors=colors[i], edgecolors='black', linewidths=0.3)
elif len(e_coordinates[i]) == 4:
poly = p3dc([[e_coordinates[i][0], e_coordinates[i][1], e_coordinates[i][2], e_coordinates[i][3]]],
facecolors=colors[i], edgecolors='black', linewidths=0.3)
ax.add_collection3d(poly)
plt.show()
The array e_coordinates
specifies the polygon shape and position (either its a polygon with 3 or 4 edges) and the vector colors
specifies the inital facecolors.
I am looking for something like (attention pseudo-code ;) )
polys = ax.get_collection()
polys.set_color(colors)
ax.set_collection(polys)
ax.update()
I hope I've been able to make clear what I am trying to do and that maybe someone has an helpful idea!
UPDATE: This is what I have now, but the plotting of the updated colors is not working for me...
fig = plt.figure()
ax = axes3d.Axes3D(fig)
poly = p3dc(e_coordinates, facecolor="white")
ax.add_collection3d(poly)
for j in range(0,100):
colors = color_generater(j) # my own function to get desired colors
ax.collections[0].set_facecolor(colors)
plt.draw()
plt.pause(0.01)