After the post of Etienne Tourigny about "Using/visualizing 3D data (Z values)", I realized that it was relatively easy from the Python console with matplotlib or visvis (new pure Python library for visualization of 1D to 4D data,

http://code.google.com/p/visvis/).

**1) 3D shapefile** **a) with matplotlib.meshgrid**With a 3d point shapefile, the

**shapely** module makes it very easy to extract the z coordinate:

from mpl_toolkits.mplot3d.axes3d import *

import pylab as plt

from matplotlib import cm

from matplotlib.mlab import griddata

import numpy as np

from shapely.wkb import loads

x=[]

y=[]

z=[]

for elem in layer.selectedFeatures():

geom= elem.geometry()

wkb = geom.asWkb()

x.append(loads(wkb).x)

y.append(loads(wkb).y)

z.append(loads(wkb).z)

now, with the x,y,z coordinates, we can build a grid/surface with the matplotlib.meshgrid function

xi = np.linspace(min(x), max(x))

yi = np.linspace(min(y), max(y))

X, Y = np.meshgrid(xi, yi)

Z = griddata(x, y, z, xi, yi)

and draw it in a 3D matplotlib window

fig = plt.figure()

ax = Axes3D(fig)

ax.plot_surface(X, Y, Z, rstride=5, cstride=5, cmap=cm.jet,linewidth=1, antialiased=True)

plt.show()

It is also possible to plot the points or the contours in 3D

**with visvis**import visvis

visvis.plot(x,y,z, lc='k', ls='', mc='g', mw=2, lw=2, ms='.')

visvis.surf(xi, yi, Z)

**b) with splines algorithms from scipy**It is also possible to use other interpolation algorithms like the spline interpolation class

BivariateSpline of scipy

**with matplotlib**import scipy as sp

from scipy.interpolate import SmoothBivariateSpline

spl = SmoothBivariateSpline(x,y,z)

# construction of the grid/surface

x = np.array(x)

y = np.array(y)

xn, yn = sp.mgrid[x.min():x.max():50j,y.min():y.max():50j]

zspline = spl( xn[:,0], yn[0,:])

fig = plt.figure()

ax = Axes3D(fig)

ax.plot_surface(xn, yn, zspline)

plt.show()

**with visvis**import visvis

visvis.surf(xn,yn,zspline)

**2) shapefile with z attribute**This is the same thing, but we must use the values of the attribute

**Conclusions and a plugin ?**Build a plugin seems a priori to me very complex and time consuming

- plot 3 d points is easy.

- but in other cases, all the scenarios (3D shapefile points, lines or polygons, shapefile with z attribute, interpolation algorithm, ...) should be considered before

- you need modules like shapely or matplotlib

I do not have much time to write a plugin and personally I'm very happy with the Python console, sorry.

Then, If somebody else wants to go,I can help