Quiver

Ok, I have some questions about what the protocol for

    > patch submission should be, in terms of 'completeness' of
    > the patch.

    > I have a patch for the quiver function that is half
    > done... it has converted the arrows from patches to
    > linecollections, and it will accept arbitrary X and Y
    > coordinates for the arrow positions, as suggested by Rob.
    > Unfortunetly, none of the color functionality is working.
    > Partly this is because the color functionality of
    > LineCollection is different from PolyCollection (which
    > quiver originally used) and partly because I don't
    > understand how matplotlib sets colors at all. Should I
    > submit this half finished patch so that others can have a
    > chance to improve the color function? Or should I not
    > submit until I figure out how color works and fix the
    > thing?

I don't recommend submitting patches that don't work. Rather, post
code samples here with questions in the areas you need help.

    > Furthermore, can LineCollection actually do all the things
    > that quiver's old color commands demand of it? I don't
    > see a place to set a colormap for a LineCollection, but as
    > I said, I don't understand it very well.

You can create a line collection that is color mappable by deriving
from LineCollection and ScalarMappable. It will take a little more
work to fully integrate it into the colormappable framework, eg so
colorbars and interactive changing of colormaps works as expected, but
this may be enough to speed you along

This is a good example of how you can extend and specialize the
existing classes if they don't behave like you want them to.

from matplotlib.colors import normalize
from matplotlib.cm import ScalarMappable, jet
from matplotlib.collections import LineCollection

from pylab import figure, show, nx
class LineCollectionSM(LineCollection, ScalarMappable):
    def __init__(self,
                 segments,
                 x,
                 norm,
                 cmap,
                 # and the other args for LineCollection
                 ):
        LineCollection.__init__(self, segments)
        ScalarMappable.__init__(self, norm, cmap)
        self.set_array(x)
        
    def draw(self, renderer):
        self._colors = self.to_rgba(self.get_array())
        LineCollection.draw(self, renderer)

def random_segment():
    x1, y1, x2, y2 = nx.mlab.rand(4)
    return (x1, y1), (x2, y2)
segments = [random_segment() for i in range(50)]
x = nx.mlab.rand(50)
col = LineCollectionSM(segments, x, normalize(), jet)
fig = figure()
ax = fig.add_subplot(111, xlim=(0,1), ylim=(0,1), autoscale_on=False)
ax.add_collection(col)
show()

You can create a line collection that is color mappable by deriving
from LineCollection and ScalarMappable. It will take a little more
work to fully integrate it into the colormappable framework, eg so
colorbars and interactive changing of colormaps works as expected, but
this may be enough to speed you along

John,

Is there any reason not to simply make LineCollection inherit from ScalarMappable the same way that PatchCollection does? I don't see any real disadvantage or backwards incompatibility, and I think it would be useful and add consistency. I can do it today, barring unforseen problems with related changes I am making.

Eric