On 07/25/2011 08:21 AM, Ben Breslauer wrote:
> I think that I have found the problem here.  Line2D.draw() (and I
> presume other Artist subclasses) calls
>
> gc.set_foreground(self._color)
> ...
> gc.set_alpha(self._alpha)
>
> self._color is defined by the color kwarg, whether it be a hex value,
> 3-tuple, 4-tuple, or something else.  self._alpha is defined by the
> alpha kwarg, but if the alpha kwarg is None, it is not overwritten with
> color[3].  Therefore, using color=(R,G,B,A) does not set alpha
> correctly.  I'm not sure the best (i.e. most matplotlib-like) way to
> change this so that the A value gets used iff alpha is None, but I've
> attached a patch that does it one way (diff'ed against the github
> master, commit 67b1cd650f574f9c53ce).  I know the patch is less than
> ideal, as it adds kwarg-specific handling into a place where none had
> previously been done, and it's also in a for loop. Maybe it would be
> better to do the checking along with the scalex and scaley pops?


Alpha handling is a real can of worms; it has gotten better, but as you 
note, there are still problems.  Unfortunately, I don't think your 
proposed solution will work in general, because self._color could be a 
4-letter string, like "gray", in which case alpha would be set to "y", 
and that would not be good at all.  I suspect the right place to solve 
the problem is down in the GraphicsContext--although I thought I had 
already straightened that out some time ago.

As Ben notes, you should file a bug report.
Given that the handling of colors and alpha is inherently tricky (and 
backend-dependent--ps doesn't support alpha at all), solving the problem 
well is going to take a bit of time and care, most likely--and testing 
to make sure that a fix in one place doesn't cause a bug in another.  I 
think we should leave it alone until after the next release.

Eric

>
>
> Separately, I noticed that
> backend_bases.GraphicsContextBase.set_foreground claims to only expect
> an RGB definition, and not an RGBA definition.  As such, I think that it
> should call
>
> self._rgb = colors.colorConverter.to_rgb(fg)
>
> instead of
>
> self._rgb = colors.colorConverter.to_rgba(fg)
>
> since that will make self._rgb a 3-tuple instead of a 4-tuple.
>
> Ben
>
> On Sat, Jul 23, 2011 at 3:13 PM, Ben Breslauer <bbresla...@gmail.com
> <mailto:bbresla...@gmail.com>> wrote:
>
>     Hi,
>
>     I'm trying to fade some data, using alpha values, that I am plotting
>     with Axes.plot().  I can recreate this problem with 1 line of
>     pylab.plot.  If I use
>
>     pylab.plot([1,2,3],[1,4,9], color=(1,0,0,.2), linewidth=7)
>
>     then I get the equivalent of
>
>     pylab.plot([1,2,3],[1,4,9], color=(1,0,0), linewidth=7)
>
>     i.e. it does not use the alpha value.  However, if instead I use
>
>     pylab.plot([1,2,3],[1,4,9], color=(1,0,0), linewidth=7, alpha=.2)
>
>     then the line is faded out appropriately.  The plot documentation
>     indicates that RGBA tuples should be valid, so I'm wondering if this
>     is a bug.  Maybe alpha is defaulting to 1 or None and then not being
>     overwritten if color is a 4-tuple?
>
>     I'm using Arch Linux with kernel 2.6.39, matplotlib 1.0.1 from the
>     Arch repo, and the Qt4 backend.  My installed Qt version is 4.7.3,
>     and I am using KDE 4.6.5.  Below is verbose-debug output.  Thanks
>     for any help!
>
>     Ben
>
>
>     $HOME=/home/ben
>     CONFIGDIR=/home/ben/.matplotlib
>     matplotlib data path
>     /usr/lib/python2.7/site-packages/matplotlib/mpl-data
>     loaded rc file
>     /usr/lib/python2.7/site-packages/matplotlib/mpl-data/matplotlibrc
>     matplotlib version 1.0.1
>     verbose.level debug
>     interactive is False
>     units is False
>     platform is linux2
>     loaded modules: ['heapq', 'numpy.core.info
>     <http://numpy.core.info>', 'distutils', 'numpy.lib.format',
>     'functools', 'pylab', '_bisect', 'subprocess', 'sysconfig', 'gc',
>     'matplotlib.tempfile', 'distutils.sysconfig', 'ctypes._endian',
>     'encodings.encodings', 'pyparsing', 'matplotlib.colors',
>     'numpy.core.numerictypes', 'numpy.testing.sys',
>     'numpy.lib.__future__', 'numpy.fft.types', 'numpy.ma.cPickle',
>     'struct', 'numpy.matrixlib.defmatrix', 'numpy.random.info
>     <http://numpy.random.info>', 'tempfile', 'numpy.compat.types',
>     'pprint', 'numpy.linalg', 'matplotlib.threading',
>     'numpy.core.machar', 'numpy.testing.types', 'numpy.testing',
>     'collections', 'numpy.polynomial.sys', 'unittest.sys',
>     'numpy.core.umath', 'unittest.main', 'distutils.types',
>     'numpy.testing.operator', 'numpy.core.scalarmath', 'numpy.ma.sys',
>     'zipimport', 'string', 'matplotlib.subprocess', 'numpy.testing.os',
>     'unittest.functools', 'numpy.lib.arraysetops',
>     'numpy.testing.unittest', 'numpy.lib.math', 'encodings.utf_8',
>     'matplotlib.__future__', 'unittest.types', 'unittest.util',
>     'numpy.testing.re <http://numpy.testing.re>', 'numpy.version',
>     'numpy.lib.re <http://numpy.lib.re>', 'distutils.re
>     <http://distutils.re>', 'numpy.matrixlib.sys', 'ctypes.os',
>     'numpy.core.os', 'numpy.lib.type_check', 'numpy.compat.sys',
>     'unittest.StringIO', 'bisect', 'numpy.core._internal', 'signal',
>     'numpy.lib.types', 'numpy.lib._datasource', 'random',
>     'numpy.lib.__builtin__', 'numpy.fft.fftpack_lite',
>     'matplotlib.cbook', 'textwrap', 'numpy.core.multiarray',
>     'numpy.polynomial.string', 'distutils.version', 'cStringIO',
>     'numpy.polynomial', 'numpy.numpy', 'matplotlib.StringIO',
>     'unittest.time', 'locale', 'numpy.add_newdocs', 'unittest.difflib',
>     'numpy.core.getlimits', 'base64', '_ssl', 'numpy.lib.sys',
>     'encodings', 'numpy.ma.itertools', 'unittest.pprint', 'unittest.re
>     <http://unittest.re>', 'abc', 'numpy.matrixlib', 'numpy.ctypes',
>     'numpy.testing.decorators', 'matplotlib.warnings', 'rfc822',
>     'numpy.lib.npyio', 'numpy.lib.numpy', 'matplotlib.sys', 're',
>     'numpy.lib._compiled_base', 'numpy.polynomial.legendre',
>     'threading', 'new', 'numpy.ma.warnings', 'numpy.random.mtrand',
>     'urllib2', 'matplotlib.cPickle', 'math', 'numpy.fft.helper',
>     'fcntl', 'unittest.case', 'matplotlib.numpy', 'UserDict',
>     'unittest.suite', 'numpy.lib.function_base', 'distutils.os',
>     'matplotlib', 'numpy.fft.numpy', 'exceptions', 'numpy.lib.info
>     <http://numpy.lib.info>', 'ctypes', 'numpy.lib.warnings',
>     'ctypes.struct', 'codecs', 'numpy.core._sort', 'numpy.os',
>     'unittest.loader', '_functools', '_locale', 'numpy.__builtin__',
>     'matplotlib.os', 'thread', 'StringIO', 'numpy.core.memmap',
>     'traceback', 'numpy.testing.warnings', 'weakref', 'itertools',
>     'numpy.fft.fftpack', 'numpy.linalg.lapack_lite', 'numpy.ma
>     <http://numpy.ma>', 'distutils.sys', 'os', 'marshal',
>     'numpy.lib.itertools', '__future__', '_collections', 'urllib',
>     'matplotlib.traceback', '_sre', 'unittest', 'numpy.core.sys',
>     'numpy.random', 'numpy.linalg.numpy', '__builtin__',
>     'numpy.lib.twodim_base', 'numpy.ma.core', 'matplotlib.re
>     <http://matplotlib.re>', 'numpy.core.cPickle', 'unittest.runner',
>     'operator', 'numpy.polynomial.polytemplate',
>     'numpy.core.arrayprint', 'distutils.string',
>     'numpy.lib.arrayterator', 'select', 'ctypes._ctypes', '_heapq',
>     'ctypes.sys', 'matplotlib.errno', 'unittest.collections',
>     'posixpath', 'numpy.lib.financial', 'numpy.polynomial.laguerre',
>     'matplotlib.random', 'errno', '_socket', 'binascii',
>     'sre_constants', 'datetime', 'numpy.core.shape_base', 'os.path',
>     'numpy.core.function_base', 'numpy.compat.py3k',
>     'numpy.lib.stride_tricks', 'numpy.core.numpy', 'numpy', '_warnings',
>     'numpy.polynomial.chebyshev', 'matplotlib.types', 'cPickle',
>     'encodings.__builtin__', 'numpy.polynomial.warnings',
>     'matplotlib.new', '_codecs', 'numpy.lib.operator',
>     'unittest.fnmatch', 'numpy.polynomial.polynomial',
>     'numpy.__config__', 'pwd', 'matplotlib.pyparsing', 'httplib',
>     'numpy.lib.ufunclike', 'copy', 'numpy.core.re
>     <http://numpy.core.re>', '_struct', 'numpy.core.fromnumeric',
>     'hashlib', 'numpy.ctypeslib', 'keyword', 'array',
>     'numpy.lib.scimath', 'numpy.fft', 'numpy.lib', 'numpy.ma.numpy',
>     'numpy.random.numpy', 'matplotlib.urllib2', 'unittest.weakref',
>     'numpy.ma.extras', 'numpy.polynomial.__future__', 'posix',
>     'encodings.aliases', 'matplotlib.fontconfig_pattern', 'fnmatch',
>     'sre_parse', 'pickle', 'numpy.core.ctypes', 'mimetools',
>     'distutils.distutils', 'unittest.signal', 'copy_reg', 'sre_compile',
>     '_hashlib', '_random', '_ctypes', 'site', 'numpy.lib.polynomial',
>     'numpy.compat', 'numpy._import_tools', 'numpy.polynomial.hermite',
>     '__main__', 'numpy.fft.info <http://numpy.fft.info>',
>     'numpy.core.records', 'shutil', 'numpy.lib.cPickle', 'numpy.sys',
>     'numpy.polynomial.hermite_e', 'urlparse', 'unittest.result',
>     'strop', 'grp', 'linecache', 'numpy.polynomial.numpy',
>     'numpy.core.numeric', 'numpy.linalg.info
>     <http://numpy.linalg.info>', 'encodings.codecs', '_abcoll',
>     'numpy.core', 'matplotlib.locale', 'matplotlib.rcsetup',
>     'matplotlib.time', 'matplotlib.weakref', 'genericpath', 'stat',
>     'socket', 'numpy.lib._iotools', 'numpy.lib.index_tricks',
>     'numpy.testing.utils', 'warnings', 'numpy.lib.utils',
>     'numpy.core.defchararray', 'numpy.polynomial.polyutils',
>     'numpy.lib.shape_base', 'numpy.core.types', 'unittest.signals',
>     'sys', 'numpy.core.warnings', 'numpy.compat._inspect',
>     'numpy.core.__builtin__', 'ctypes.ctypes',
>     'numpy.testing.traceback', 'numpy.lib.os',
>     'numpy.testing.nosetester', 'types', 'numpy.lib.shutil',
>     'matplotlib.datetime', 'matplotlib.distutils', '_weakref',
>     'numpy.testing.numpytest', 'difflib', 'distutils.errors',
>     'numpy.matrixlib.numpy', 'matplotlib.matplotlib', '_weakrefset',
>     'matplotlib.shutil', 'numpy.lib.cStringIO', 'unittest.warnings',
>     'time', 'unittest.traceback', 'ssl', 'numpy.linalg.linalg',
>     'unittest.os', 'numpy.testing.numpy']
>     Using fontManager instance from /home/ben/.matplotlib/fontList.cache
>     backend Qt4Agg version 0.9.1
>     findfont: Matching
>     
> :family=sans-serif:style=normal:variant=normal:weight=normal:stretch=normal:size=medium
>     to Bitstream Vera Sans
>     (/usr/lib/python2.7/site-packages/matplotlib/mpl-data/fonts/ttf/Vera.ttf)
>     with score of 0.000000
>
>
>
>
> ------------------------------------------------------------------------------
> Storage Efficiency Calculator
> This modeling tool is based on patent-pending intellectual property that
> has been used successfully in hundreds of IBM storage optimization engage-
> ments, worldwide.  Store less, Store more with what you own, Move data to
> the right place. Try It Now! http://www.accelacomm.com/jaw/sfnl/114/51427378/
>
>
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users


------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model 
configuration take the hassle out of deploying and managing Subversion and 
the tools developers use with it. Learn more about uberSVN and get a free 
download at:  http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to