I have a cube of which I know the x,y,z positions of its vertices, I also have an array relating faces to vertices (the faces are composed of 2 triangles):
import numpy as np
x = np.array([ 0.16257299, -0.370805 , -1.09232295, 1.62570095,
-1.62570095, 1.09232295, 0.370805 , -0.16257299])
y = np.array([-1.71022499, -0.81153202, -0.52910602, -0.36958599,
0.369587 , 0.52910602, 0.81153202, 1.71022499])
z = np.array([ 0.22068501, -1.48456001, 1.23566902, 0.469576 ,
-0.469576 , -1.23566902, 1.48456001, -0.22068501])
faces = ([[3, 0, 1],[6, 7, 4],[3, 6, 2],[0, 2, 4],[1, 4, 7],[6, 3, 5],
[1, 5, 3],[4, 2, 6],[2, 0, 3],[4, 1, 0],[7, 5, 1],[5, 7, 6]])
I manage to plot the 3D visualization of the cube with the following:
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.plot_trisurf(x,y,z, triangles = faces)
But what I would like is to plot the 2D projection of the cube on the Y axis, I tried the following:
valuesOfFaces = [5,10,9,1,2,3,7,8]
import matplotlib.pyplot as plt
%matplotlib notebook
fig, ax = plt.subplots()
ax.tricontourf(x,z,valuesOfFaces,triangles = faces,zdir='y',levels=np.sort(valuesOfFaces))
But it results in the following:
What I would like is to be able to color each face given a constant value and also that faces that are not visible do not appear. Is that possible with matplotlib ? If yes how would you suggest I proceed ?