SourceForge logo
SourceForge logo
Menu

Re: [matplotlib-devel] LineCollection and alpha

From: Michael D. <md...@st...> - 2008年03月18日 18:41:32
That seems like a reasonable fix. Fixed in SVN r5003.
Cheers,
Mike
Michael Fitzgerald wrote:
> Hi all,
>
> I found a small bug in LineCollection, which gives an exception when 
> setting alpha. This is manifested in e.g. hlines and vlines:
>
>> In [1]: hlines((0,),(-1,),(1,),color='b',alpha=0.1)
>> ---------------------------------------------------------------------------
>> IndexError Traceback (most recent call 
>> last)
>>
>> XXX/<ipython console> in <module>()
>>
>> XXX/lib/python/matplotlib/pyplot.py in hlines(*args, **kwargs)
>> 1700 hold(h)
>> 1701 try:
>> -> 1702 ret = gca().hlines(*args, **kwargs)
>> 1703 draw_if_interactive()
>> 1704 except:
>>
>> XXX/lib/python/matplotlib/axes.py in hlines(self, y, xmin, xmax, 
>> colors, linestyles, label, **kwargs)
>> 2609 linestyles=linestyles, 
>> label=label)
>> 2610 self.add_collection(coll)
>> -> 2611 coll.update(kwargs)
>> 2612
>> 2613 minx = min(xmin.min(), xmax.min())
>>
>> XXX/lib/python/matplotlib/artist.py in update(self, props)
>> 438 if func is None or not callable(func):
>> 439 raise AttributeError('Unknown property %s'%k)
>> --> 440 func(v)
>> 441 changed = True
>> 442 self.eventson = store
>>
>> XXX/lib/python/matplotlib/collections.py in set_alpha(self, alpha)
>> 306 else:
>> 307 artist.Artist.set_alpha(self, alpha)
>> --> 308 self._facecolors[:, 3] = alpha
>> 309 self._edgecolors[:, 3] = alpha
>> 310
>>
>> IndexError: invalid index
>
>
> This appears to be because LineCollection.__init__() only uses 
> Collection._edgecolors, and sets _facecolors to an empty array. I 
> don't know if it's the proper solution, but I did this to get it to work:
>
> Index: lib/matplotlib/collections.py
> ===================================================================
> --- lib/matplotlib/collections.py (revision 5000)
> +++ lib/matplotlib/collections.py (working copy)
> @@ -305,7 +305,8 @@
> except TypeError: raise TypeError('alpha must be a float')
> else:
> artist.Artist.set_alpha(self, alpha)
> - self._facecolors[:, 3] = alpha
> + if len(self._facecolors):
> + self._facecolors[:, 3] = alpha
> self._edgecolors[:, 3] = alpha
>
> def get_linewidths(self):
>
>
> Best,
> Mike
>
> ------------------------------------------------------------------------
>
> -------------------------------------------------------------------------
> This SF.net email is sponsored by: Microsoft
> Defy all challenges. Microsoft(R) Visual Studio 2008.
> http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
> ------------------------------------------------------------------------
>
> _______________________________________________
> Matplotlib-devel mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel
> 

View entire thread

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /