I can’t tell if I’m misusing collections here, or if there is a bug. Anyway, what I’m trying to do is keep track of a group of rectangles generated from a bar plot. Instead of letting there be a large number of artists added to the axes, I wanted to just group them into a collection and add the collection instead. As in the code below:

#!/usr/bin/env python

import numpy

import matplotlib.pyplot as plt

import matplotlib.collections

# just generate some data to plot

x = numpy.linspace(0.0,2.0*numpy.pi,10)

y = numpy.sin(x)

# plot

axes = plt.gca()

bars = plt.bar(x,y,color=‘red’,width=0.1)

# strip out all of the newly inserted rectangles

for b in bars: b.remove()

# and create a collection for plotting the rectangles instead.

coll = matplotlib.collections.PatchCollection(bars)

axes.artists.append(coll)

plt.xlim(0.0,2.0*numpy.pi)

plt.grid(True)

plt.show()

This appears to work at first blush, but if you resize the plot, you can tell that the rectangles are just fixed in their location now. I tried messing around with setting the transform for the new collection object “coll” in different ways, to no avail. Any suggestions welcome

## ···

–

Daniel Hyams

dhyams@…287…