On Tue, May 19, 2009 at 2:21 AM, Jean-Christophe Penalva
<jean-christophe.pena...@cines.fr> wrote:
>  i'm trying to use matplotlib to draw some rectangles on one screen. Every
> rectangle has is own position (x,y) is own size, and each of them must have a
> fill color in a colormap.
>  Is there an example somewhere ?
>


Easiest is to use a matplotlib.collections.PolyCollection, which is
already setup for colormapping::
    import numpy as np
    import matplotlib.collections as collections
    import matplotlib.cm as cm
    import matplotlib.pyplot as plt

    N = 100

    verts = [((x, y), (x, y+height), (x+width, y+height), (x+width,
y)) for (x,y,width,height) in np.random.rand(N,4)]
    intensities = np.random.rand(N)

    c = collections.PolyCollection(verts)
    c.set_array(intensities)
    c.set_cmap(cm.hot)

    fig = plt.figure()
    ax = fig.add_subplot(111)
    ax.add_collection(c)
    ax.set_xlim(-1,2)
    ax.set_ylim(-1,2)

    plt.show()

JDH

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables 
unlimited royalty-free distribution of the report engine 
for externally facing server and web deployment. 
http://p.sf.net/sfu/businessobjects
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to