On Tue, Feb 14, 2012 at 12:49 PM, Olе Streicher <ole-usenet-s...@gmx.net>wrote:

> Jerzy Karczmarczuk
> <jerzy.karczmarc...@unicaen.fr> writes:
> > Could you provide a /working/ example with the geometry you really want?
> > I believe I thought more or less about it as Tony Yu did. If it is
> > wrong, be more precise, please.
>
> I have a data set that looks like this:
>
> mydata = numpy.copy([
>
> # lambda,  data
>
> # First data row
>  [[5002., 0.5],
>  [5200., 0.34],
>  [5251., -1.2],
> #  ...
>  [8997., 2.4]],
>
> # second data row
>  [[5002., 0.72],
>  [5251., 0.9],
> #  ...
>  [8997.,  0.1]],
>
> # other data rows to follow
> #  ...
>  ])
>
> where I want to put the first column (lambda) on the Y axis, which each
> data row as one colorbar (like in your code), and the data as the color
> of that data point -- interpolated vertically.
>
> Best regards
>
> Ole
>
>
OK, I see now.

Unfortunately, this makes it quite a bit more complex, but it's still
doable. Part of the complexity arises because of (what I believe to be) a
quirk in NonUniformImage: You can pass an extent argument, but this only
rescales the data---it doesn't clip the data. You have to manually clip the
borders of each bar.

Here's an example:

#---
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.image import NonUniformImage

width = 0.5
height = 10

ax = plt.gca()

for x0 in np.arange(11):
    y = np.sort(np.random.uniform(high=height, size=10))
    z = np.random.random(size=(10, 1))
    # Note NonUniformImage fails with single column; double up data
    z = np.repeat(z, 2, axis=1)
    x = [x0, x0]

    extent = (x0-width/2., x0+width/2, y[0], y[-1])
    im = NonUniformImage(ax, interpolation='bilinear', extent=extent)
    im.set_data(x, y, z)

    # clip image
    x_left = extent[0]
    xm = [x_left, x_left + width, x_left + width, x_left]
    ym = [0, 0, height, height]
    mask, = ax.fill(xm, ym, facecolor='none', edgecolor='none')
    im.set_clip_path(mask)

    ax.images.append(im)

ax.set_xlim(-width, x0+width)

plt.show()
#---

HTH,
-Tony
------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing 
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to