Ray Speth wrote: > I believe I have found a simple change that improves the rendering speed > of quiver plots, which can be quite slow for large vector fields. Based > on some profiling, the problem appears to stem from the use of numpy's > MaskedArrays in PolyCollection.set_verts. If I add the following line to > the top of the PolyCollection.set_verts function in collections.py: > > verts = np.asarray(verts) > > I find that quiver plots are drawn about 3 times as quickly, going from > 2.6 seconds for a 125x125 field to 0.65 seconds. This does not seem to > break the use of MaskedArrays as inputs, and masked regions are still > hidden in the final plot. I do not know if this has any adverse effects > in other classes that inherit from PolyCollection. > > Using: > python 2.6.2 on Windows XP > numpy 1.3.0 > matplotlib 0.98.5.3, Qt4Agg backend > > I do not know why iterating over MaskedArrays is so slow, but perhaps > this information can be used to speed up some other functions as well. >
Ray, I was not aware of this particular slowdown, but yes, masked arrays are frustratingly slow in many ways. There is no inherent reason they can't be nearly as fast as ndarrays for almost everything, but it will take quite a bit of work at the C level to get there. In the meantime, there are often other ways of getting around critical slowdowns. Thanks for the quiver tip; I will look into it. Offhand, I suspect a modified version of your suggestion will be needed, but we should be able to get the speedup you found one way or another. I think that your suggested change would effectively disable all masked array support in PolyCollection, and I don't want to do that. Eric > Ray Speth > > ------------------------------------------------------------------------------ > _______________________________________________ > Matplotlib-devel mailing list > Matplotlib-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/matplotlib-devel ------------------------------------------------------------------------------ _______________________________________________ Matplotlib-devel mailing list Matplotlib-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-devel