# -*- coding: utf-8 -*-

import numpy as np

##*********************************************************
##*********************************************************

## 2D collection
import matplotlib.pyplot as plt
import matplotlib.collections as collections



vertsQuad = [ np.array([ [0.,0.], [0.,1.], [1.,1.], [1.,0.] ]),
#          np.array([ [0.,1.], [2.,3.], [2.,2.], [1.,1.] ]),
#          np.array([ [2.,2.], [2.,3.], [4.,1.], [3.,1.] ]),
          np.array([ [3.,0.], [3.,1.], [4.,1.], [4.,0.] ])]

vertsQuad = np.array([ [0, 0], [0, 1], [2, 3], [4, 1], [4, 0], [3, 0],
                       [3, 1], [2, 2], [1, 1], [1, 0] ])

## 3D collection
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.cm as cm # colormaps

fig = plt.figure()
ax = Axes3D(fig)

colors = ['r', 'g', 'b', 'y', 'k']
zpos = [0,1,2,3,4]

verts = [vertsQuad] * len(zpos)

#for i, c in zip(zpos, colors):
poly = collections.PolyCollection(verts, linewidth=0.25)
poly.set_alpha(0.7)# collection transparency (opaque == 1), needed for projection bug workaround!
poly.set_color(colors)

  ## need to have a z-value for *each* polygon = element!
  #zs = [i]*len(vertsQuad)
  ## alternatively:
  #elemno = len(col.get_paths())
  #zs = [i]*elemno

ax.add_collection3d(poly, zs=zpos, zdir='y')

## axis limit settings:
ax.set_xlim3d(0,4)
ax.set_zlim3d(0,3)
ax.set_ylim3d(0,4)
#ax.set_title(title)
ax.set_xlabel('x')
ax.set_ylabel('slice')
ax.set_zlabel('y')

#pylab.draw()
plt.show()
#pylab.savefig('example_mplCollection_3D')
