Thanks so much Tony...that does indeed work. I'm not sure if I understand
exactly why, but I'll continue to bang my head on it for a while ;)
The set_transform() call is needed if you throw the collection into the
axes.artists list, but not if axes.add_collection() is used to (ahem) add
the collection.
On Fri, Dec 9, 2011 at 5:27 PM, Tony Yu <tsy...@gmail.com> wrote:
>
> On Fri, Dec 9, 2011 at 5:23 PM, Tony Yu <tsy...@gmail.com> wrote:
>
>>
>>
>> On Fri, Dec 9, 2011 at 4:11 PM, Daniel Hyams <dhy...@gmail.com> wrote:
>>
>>> I'm sorry, I should have stated the version. I'm using 1.0.0, which
>>> just returns a list of rectangle artists.
>>>
>>>
>>> On Fri, Dec 9, 2011 at 4:08 PM, Benjamin Root <ben.r...@ou.edu> wrote:
>>>
>>>> On Fri, Dec 9, 2011 at 2:55 PM, Daniel Hyams <dhy...@gmail.com> wrote:
>>>>
>>>>> Tried, but unfortunately it did not make any difference :(
>>>>>
>>>>>
>>>> Just as an interesting point... don't know if it means anything. In
>>>> v1.1.x, we now return a "BarContainer" from the bar() function. This
>>>> container subclasses the tuple type, which is why you are still able to
>>>> treat it like a list. Anyway, this class does a bunch of things that I
>>>> wonder if it could be interfering with what you are trying to do. Probably
>>>> not, but still...
>>>>
>>>> Ben Root
>>>>
>>>>
>>>
>>>
>>> --
>>> Daniel Hyams
>>> dhy...@gmail.com
>>>
>>
>> So I think the problem is that ``plt.bar`` assigns a transform to each
>> patch (as it should). But then when pass these patches to PatchCollection,
>> the collection applies it's own transform (but doesn't ignore the patch's
>> transform, apparently). The solution is to clear out the transform on each
>> patch---where "clearing" a transform translates to setting it to the
>> IdentityTransform.
>>
>> Below is code that works *on my system*. It sounds like it will work
>> slightly differently on your system:
>>
>>
>> #!/usr/bin/env python
>> import numpy
>> import matplotlib.pyplot as plt
>> import matplotlib.collections
>> import matplotlib.transforms as transforms
>>
>>
>> # 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)
>>
>> axes.patches = []
>> for p in bars.patches:
>> p.set_transform(transforms.IdentityTransform())
>>
>> ## and create a collection for plotting the rectangles instead.
>> coll = matplotlib.collections.PatchCollection(bars.patches)
>>
>> coll.set_transform(axes.transData)
>> axes.add_collection(coll, autolim=True)
>>
>> plt.xlim(0.0,2.0*numpy.pi)
>> plt.grid(True)
>> plt.show()
>>
>>
>>
> P.S. you don't need the call to set_transform that I accidentally added.
>
--
Daniel Hyams
dhy...@gmail.com
------------------------------------------------------------------------------
Learn Windows Azure Live! Tuesday, Dec 13, 2011
Microsoft is holding a special Learn Windows Azure training event for
developers. It will provide a great way to learn Windows Azure and what it
provides. You can attend the event by watching it streamed LIVE online.
Learn more at http://p.sf.net/sfu/ms-windowsazure
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users