Dear Ben,

again, thanks for all your support! Still, I am unable to get the plot
done. In your example, each set of elements gets a color where as I
need each element to have its own color.

I'll attach a file to demonstrate. Maybe you know how to get this
done, and sorry that I am a bit slow on this :(

Best regards,
Daniel
import sys
import scipy,pylab
import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D

##------------------------------------------------------------------------------
def closePolys(elements):
  '''
  close the open polygon elements by adding the first node of each poly again.
  '''
  closed = []
  for nodes in elements:
    i = nodes[0]
    ii = list(nodes)
    ii.append(i)
    closed.append(ii)
  return closed

elements = [ [ (0,0), (0,1), (1,1), (1,0) ],
          [ (4,1), (2,3), (2,2), (3,1)],
          [ (0,1), (2,3), (2,2), (1,1)],
          [ (3,0), (3,1), (4,1), (4,0)]]
data = scipy.rand(4)

polys = closePolys(elements)

##------------------------------------------------------------------------------
colors = ['r', 'g', 'b', 'y', 'k']
zpos = [0,1,2,3,4]
zs = []
cs = []
for z, c in zip(zpos, colors) :
    zs.extend([z] * len(polys))
    cs.extend([c] * len(polys))

allPolys = polys * len(zpos)

poly = mpl.collections.PolyCollection(allPolys, linewidth=0.25, closed=False)
#poly.set_color('r')
poly.set_color(cs)

fig = pylab.figure()
ax = Axes3D(fig)
ax.add_collection3d(poly, zs=zs, zdir='y')

## axis limit settings:
ax.set_xlim3d(0,4)
ax.set_zlim3d(0,3)
ax.set_ylim3d(0,4)

## labels:
ax.set_title('Works')
ax.set_xlabel('x')
ax.set_ylabel('slice')
ax.set_zlabel('y')

##------------------------------------------------------------------------------
fig = pylab.figure()
ax = Axes3D(fig)

stacks = 3
zpos = scipy.arange(stacks)

collist = []
for i in range(stacks):
  col = mpl.collections.PolyCollection(polys, linewidths=0.05, closed=False) # thin elements lines (good for bw plot)
  col.set_array(data)
  collist.append(col)

for i,col in enumerate(collist):
  col.set_cmap(mpl.cm.cool)
  ## get number of elements per collection
  elemno = len(col.get_paths())
  ## create *iterable* for the 3D collection slices [z,z,z,...,z]
  zs = [zpos[i]]*elemno
  col.autoscale()
  ax.add_collection3d(col, zs=zs, zdir='y')
  pylab.draw()

## axis limit settings:
ax.set_xlim3d(0,4)
ax.set_zlim3d(0,3)
ax.set_ylim3d(-0.1,stacks-1+0.1)

## labels:
ax.set_title('Doesn\'t work')
ax.set_xlabel('x')
ax.set_ylabel('slice')
ax.set_zlabel('y')

##------------------------------------------------------------------------------
pylab.show()
------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand 
malware threats, the impact they can have on your business, and how you 
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to