2
votes

I've calculated some values representing a potential as a function of x,y using relaxation method. And I want to display a contour plot with colors (not lines) but, the examples at matplotlib are all fancy 3d plots. I have a ufinal object which is a 2 dimensional numpy array. I did see some nice answers with very nice plots here on SO but I wasn't able to use them properly with my data. I was able to plot a 3d plot using the examples but that's not what I need:

fig = plt.figure()
ax = fig.gca(projection='3d')

X,Y=meshgrid(x,y)

surf=ax.plot_surface(X,Y,ufinal,rstride=1,cstride=1,cmap=cm.jet,linewidth=0.1)
fig.colorbar(surf,shrink=0.5,aspect=5)

As suggested I've tried using the contourf example like so:

CS = plt.contourf(X, Y, ufinal,cmap=cm.jet)
plt.clabel(CS, inline=1, fontsize=10)
plt.title('Simplest default with labels')
2

2 Answers

3
votes

As David said, use contourf:

import numpy as np
import pylab as pl

x,y = np.mgrid[:1:1E-3,:1:1E-3]
xs = ((x-0.3)**2.)
ys = ((y-0.5)**2.)
z = np.exp(-1*(xs/0.5+ys/0.3))

pl.contourf(x,y,z,20)
-1
votes

In case anyone is still interested I found a solution for the granularity (a.k.a. nice-looking-ness problem) as part of the solution over here: Symmetrical Log color scale in matplotlib contourf plot