title: Plot 3D convex closed regions in matplotlib
body: <p>I am trying to plot in 3D a polytope defined by a set of inequalities. Essentially, I try to reproduce the functionality of this matlab <a href="https://www.mathworks.com/matlabcentral/fileexchange/9261-plot-2d-3d-region?focused=5143921&amp;tab=function" rel="noreferrer">plotregion</a> library in matplotlib.</p>
  
  <p>My approach is to get the intersection vertices, construct the convex hull of them, and then get and plot the resulting faces (simplices).</p>
  
  <p>The problem is that many simplices are coplanar, and they are making the plot very busy for no reason (see all of these diagonal edges in the plot below).</p>
  
  <p>Is there any easy way to just print the "outside" edges of the polyhedron, without having to consolidate by my self, one by one, all of the coplanar simplices?</p>
  
  <p>Thank you</p>
  
  <pre><code>from scipy.spatial import HalfspaceIntersection
  from scipy.spatial import ConvexHull
  import scipy as sp
  import numpy as np
  import matplotlib.pyplot as plt
  import mpl_toolkits.mplot3d as a3
  import matplotlib.colors as colors
  
  
  w = np.array([1., 1., 1.])
  
  
  # ∑ᵢ hᵢ wᵢ qᵢ - ∑ᵢ gᵢ wᵢ &lt;= 0 
  #  qᵢ - ubᵢ &lt;= 0
  # -qᵢ + lbᵢ &lt;= 0 
  halfspaces = np.array([
                      [1.*w[0], 1.*w[1], 1.*w[2], -10 ],
                      [ 1.,  0.,  0., -4],
                      [ 0.,  1.,  0., -4],
                      [ 0.,  0.,  1., -4],
                      [-1.,  0.,  0.,  0],
                      [ 0., -1.,  0.,  0],
                      [ 0.,  0., -1.,  0]
                      ])
  feasible_point = np.array([0.1, 0.1, 0.1])
  hs = HalfspaceIntersection(halfspaces, feasible_point)
  verts = hs.intersections
  hull = ConvexHull(verts)
  faces = hull.simplices
  
  ax = a3.Axes3D(plt.figure())
  ax.dist=10
  ax.azim=30
  ax.elev=10
  ax.set_xlim([0,5])
  ax.set_ylim([0,5])
  ax.set_zlim([0,5])
  
  for s in faces:
      sq = [
          [verts[s[0], 0], verts[s[0], 1], verts[s[0], 2]],
          [verts[s[1], 0], verts[s[1], 1], verts[s[1], 2]],
          [verts[s[2], 0], verts[s[2], 1], verts[s[2], 2]]
      ]
  
      f = a3.art3d.Poly3DCollection([sq])
      f.set_color(colors.rgb2hex(sp.rand(3)))
      f.set_edgecolor('k')
      f.set_alpha(0.1)
      ax.add_collection3d(f)
  
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/dacwb.png" rel="noreferrer"><img src="https://i.stack.imgur.com/dacwb.png" alt="Result of the above code"></a></p>