import matplotlib.pyplot as plt
from fipy.tools import numerix
from matplotlib.collections import PolyCollection
from matplotlib import colors, cm


def plot_mesh(mesh, values=None):

    vertexIDs = mesh._orderedCellVertexIDs
    vertexCoords = mesh.vertexCoords
    xCoords = numerix.take(vertexCoords[0], vertexIDs)
    yCoords = numerix.take(vertexCoords[1], vertexIDs)

    polys = []

    for x, y in zip(xCoords.swapaxes(0, 1), yCoords.swapaxes(0, 1)):
        if hasattr(x, 'mask'):
            x = x.compressed()
        if hasattr(y, 'mask'):
            y = y.compressed()
        polys.append(zip(x, y))

    collection = PolyCollection(polys)
    #collection.set_linewidth(0.3 * resolution)
    collection.set_facecolors('white')
    plt.gca().axes.add_collection(collection)

    if values:
        #     rgba = cm.cmap(plt.colors.norm(Z))
        rgba = cm.get_cmap('coolwarm')(colors.norm(Z))
        collection.set_facecolors(rgba)
        collection.set_edgecolors(rgba)

    plt.plot()
    plt.show()

@@ -58,16 +58,36 @@
 umerix%0D%0A
+import numpy as np%0D%0A
 from mat
@@ -781,16 +781,46 @@
 hite')%0D%0A
+    plt.gca().set_aspect(1.)%0D%0A
     plt.
@@ -1094,12 +1094,901 @@
 plt.show()%0D%0A
+%0D%0A%0D%0Adef plot_planar_sensor(width,%0D%0A                            pitch,%0D%0A                            n_pixel,%0D%0A                            thickness,potential_fit, V_backplane, V_readout, min_x, max_x, min_y, max_y):%0D%0A    # Plot potential%0D%0A    xnew = np.linspace(min_x, max_x, 1000)%0D%0A    ynew = np.linspace(min_y, max_y, 1000)%0D%0A    phi = potential_fit(xnew, ynew).T%0D%0A    plt.contour(xnew, ynew, phi, 15, colors='black')%0D%0A    plt.pcolormesh(xnew, ynew, phi, cmap=cm.get_cmap('Blues'), vmin=V_backplane, vmax=V_readout)%0D%0A    plt.colorbar()%0D%0A%0D%0A    # Plot E-Field%0D%0A    xnew = np.linspace(min_x, max_x, 10)%0D%0A    ynew = np.linspace(min_y, max_y, 10)%0D%0A    z_new = potential_fit(xnew, ynew).T%0D%0A    xnew, ynew = np.meshgrid(xnew, ynew)%0D%0A    E_y, E_x = np.gradient(z_new)%0D%0A    E_x, E_y = -E_x, -E_y%0D%0A    plt.streamplot(xnew, ynew, E_x, E_y, density=1.5, color='gray', arrowstyle='-')%0D%0A%0D%0A    plt.show()

add generic planar sensor field/potential plot