title: How can I plot 2d FEM results using matplotlib?
body: <p>I'm developing a 2D plane finite element tool. One of the features is the ability to visualize the stresses on a particular object.</p>
  
  <p>This tool creates a quadrilateral mesh using the following data:</p>
  
  <ul>
  <li><p><strong>nodes</strong>: numpy array <code>[[x1 y1], [x2 y2], etc]</code> -> <code>x</code> and <code>y</code> coordinates of every node in the mesh</p></li>
  <li><p><strong>elements</strong>: numpy array <code>[[1 2 3 4], [2 3 5 6]]</code> -> every line of the array corresponds to the 4 points of one particular element of the mesh.</p></li>
  </ul>
  
  <p>I was able to implement a method that plots the mesh:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import matplotlib.collections
  import matplotlib.cm as cm
  
  import numpy as np
  
  
  def showMeshPlot(nodes, elements):
  
      y = nodes[:,0]
      z = nodes[:,1]
  
      #https://stackoverflow.com/questions/49640311/matplotlib-unstructered-quadrilaterals-instead-of-triangles
      def quatplot(y,z, quatrangles, ax=None, **kwargs):
  
          if not ax: ax=plt.gca()
          yz = np.c_[y,z]
          verts= yz[quatrangles]
          pc = matplotlib.collections.PolyCollection(verts, **kwargs)
          ax.add_collection(pc)
          ax.autoscale()
  
      plt.figure()
      plt.gca().set_aspect('equal')
  
      quatplot(y,z, np.asarray(elements), ax=None, color="crimson", facecolor="None")
      if nodes:            
          plt.plot(y,z, marker="o", ls="", color="crimson")
  
      plt.title('This is the plot for: quad')
      plt.xlabel('Y Axis')
      plt.ylabel('Z Axis')
  
  
      plt.show()
  
  nodes = np.array([[0,0], [0,0.5],[0,1],[0.5,0], [0.5,0.5], [0.5,1], [1,0], 
                    [1,0.5],[1,1]])
  elements = np.array([[0,3,4,1],[1,4,5,2],[3,6,7,4],[4,7,8,5]])
  stresses = np.array([1,2,3,4])
  
  showMeshPlot(nodes, elements)
  </code></pre>
  
  <p>Which produces a plot like this:</p>
  
  <p><a href="https://i.stack.imgur.com/LItn5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/LItn5.png" alt="quad mesh"></a></p>
  
  <p>Now, i have an 1D array with the stresses on the object, with the same length as the elements array. </p>
  
  <p>My question is how can i visualize those stresses (with a scalar bar) using matplotlib? I looked into pcolormesh, but i couldn't understand how it could work with my data. Here's an example of what i want to achieve (credits to robbievanleeuwen):</p>
  
  <p><a href="https://i.stack.imgur.com/tMKag.png" rel="noreferrer"><img src="https://i.stack.imgur.com/tMKag.png" alt="example"></a></p>
  
  <p>Note: I couldn't replicate the above example because he uses a triangular mesh instead of quads.</p>
  
  <p>Thanks in advance!</p>