Tried, but unfortunately it did not make any difference :(

On Fri, Dec 9, 2011 at 2:22 PM, Tony Yu <tsy...@gmail.com> wrote:

>
>
> On Fri, Dec 9, 2011 at 2:13 PM, Daniel Hyams <dhy...@gmail.com> wrote:
>
>> 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
>> dhy...@gmail.com
>>
>> try transOffset:
>
> >>> coll = matplotlib.collections.PatchCollection(bars,
> transOffset=axes.transData)
>
> I've always found this a bit clumsy, but I think it's the standard way to
> do it.
>
> -Tony
>



-- 
Daniel Hyams
dhy...@gmail.com
------------------------------------------------------------------------------
Cloud Services Checklist: Pricing and Packaging Optimization
This white paper is intended to serve as a reference, checklist and point of 
discussion for anyone considering optimizing the pricing and packaging model 
of a cloud services business. Read Now!
http://www.accelacomm.com/jaw/sfnl/114/51491232/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to