On 01/14/2011 02:02 AM, Daniel Mader wrote:
Hi Eric,

thanks for your feedback, it helped a lot! I have some questions left,
see below.

2011/1/14 Eric Firing<efir...@hawaii.edu>:
Quick thoughts with no testing or concrete examples:

1) Don't set the cmap or norm for the colorbar; let it inherit those
properties from the mappable to which it is connected.

Am I doing this correctly in the attached code? It seems there are
several ways of doing this... Which is the suggested one? How can I
label the colorbar?

The way you did it is fine. For the label, modify by keeping a reference to the colorbar and then calling set_label:

cb = fig.colorbar(collist[-1], shrink=0.85,)#, aspect=5)
cb.set_label('whatever this is')



2) Ensure that the cmap and norm are the same for all collections.  You
are already taking care of the cmap, so the problem is that you are
autoscaling the collections separately, which is setting vmin and vmax
to different values for the different collections.  Use the data to
figure out the range (vmin, vmax) that you want the colors to span, and
then for each collection, instead of col.autoscale(), use

        col.norm.vmin = vmin
        col.norm.vmax = vmax

That was what I needed, see code :)

(You could also make a single norm instance for all the collections to
use, just as with the cmap, so that you only have to set vmin and vmax
once.)

And this I don't understandm could you please elaborate?

See attached modification.

Eric


Thanks a very lot in advance
best regards from Austria,

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)]]
tmp = scipy.array([1,1.1,0.9,1])
data = [tmp, tmp*2, tmp*4]

## workaround for bug in mpl: close polys manually, no auto-closing!
polys = closePolys(elements)

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

stacks = 3
zpos = scipy.arange(stacks)

vmin,vmax = scipy.amin(data), scipy.amax(data)
norm = mpl.colors.Normalize(vmin=vmin, vmax=vmax)
cmap = mpl.cm.cool

collist = []
for i in range(stacks):
  col = mpl.collections.PolyCollection(polys, linewidths=0.05, closed=False,
                                        norm=norm, cmap=cmap)
  col.set_array(data[i])
  collist.append(col)


for i,col in enumerate(collist):
  ## 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
  ## collection transparency (opaque == 1), needed for projection bug workaround
  col.set_alpha(0.3)

  ax.add_collection3d(col, zs=zs, zdir='y')
  #pylab.draw()

## colorbar:

cb = fig.colorbar(collist[-1], shrink=0.85,)#, aspect=5)
cb.set_label('whatever this is')


## 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('Transparency workaround')
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