3D Surface Plot Issue with colourbar
<p>I am trying to plot values of the charge density of a crystal over the x=y plane. I have been able to plot a contour map of the charge density, and a wireframe (below)</p>

<p><a href="https://i.stack.imgur.com/zHJUP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zHJUP.png" alt="Wiremesh"></a></p>

<p>But it looks a bit messy. I would like to make a surface plot, so you can see where the atoms in the crystal are better (rather than being able to 'see through' the wire plot).</p>

<p>When I use the code (bottom of this description), I get the image below:</p>

<p><a href="https://i.stack.imgur.com/hu86O.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hu86O.png" alt="Surface plot no colourbar"></a></p>

<p>Which obviously shows no colour variation. What have I done wrong here? Any help would be great!</p>

<p>Code below. Note the function "chgdens2" calculates the value of the charge density at various points in the plane. </p>

<pre><code>fig = pyplot.figure()
x = numpy.linspace(-0.5*A,0.5*A,10) #Range of x vals 
z = numpy.linspace(-0.5*A,0.5*A,10) #Range of z vals
p = numpy.sqrt(2) * x
P, Z = numpy.meshgrid(p,z)
DENS = numpy.zeros((len(p), len(z)),dtype=numpy.float32)

for i in range (len(p)):
    for j in range(len(z)):
        DENS[i, j] = chgdens2(N,n,numpy.array([x[i],x[i],z[j]]),m)

ax = fig.gca(projection='3d')
surf = ax.plot_surface(P,Z,DENS, cmap=cm.coolwarm,
                   linewidth=0, shade=True)
fig.colorbar(surf, shrink=0.5, aspect=5)
pyplot.show()
</code></pre>