Revision: 8372 http://matplotlib.svn.sourceforge.net/matplotlib/?rev=8372&view=rev Author: efiring Date: 2010-06-04 03:37:56 +0000 (Fri, 04 Jun 2010)
Log Message: ----------- alpha is left as None until you really want to specify it; closes 2957321. I think this, together with some other recent commits, fixes various longstanding problems in the way alpha has been handled. The default value is left as None, and with this value, existing alpha specified in RGBA sequences will not be overridden. Substitution of the default value of 1 for a value of None is delayed until the GraphicsContextBase set_alpha method is executed. Modified Paths: -------------- trunk/matplotlib/examples/pylab_examples/figimage_demo.py trunk/matplotlib/lib/matplotlib/artist.py trunk/matplotlib/lib/matplotlib/axes.py trunk/matplotlib/lib/matplotlib/backend_bases.py trunk/matplotlib/lib/matplotlib/cm.py trunk/matplotlib/lib/matplotlib/collections.py trunk/matplotlib/lib/matplotlib/colorbar.py trunk/matplotlib/lib/matplotlib/contour.py trunk/matplotlib/lib/matplotlib/figure.py trunk/matplotlib/lib/matplotlib/text.py Modified: trunk/matplotlib/examples/pylab_examples/figimage_demo.py =================================================================== --- trunk/matplotlib/examples/pylab_examples/figimage_demo.py 2010-06-04 02:40:00 UTC (rev 8371) +++ trunk/matplotlib/examples/pylab_examples/figimage_demo.py 2010-06-04 03:37:56 UTC (rev 8372) @@ -1,5 +1,6 @@ """ -See pcolor_demo2 for a much faster way of generating pcolor plots +This illustrates placing images directly in the figure, with no axes. + """ import numpy as np import matplotlib @@ -12,19 +13,9 @@ Z.shape = 100,100 Z[:,50:] = 1. -ax = fig.add_subplot(111) -ax.grid(True) - im1 = plt.figimage(Z, xo=50, yo=0, cmap=cm.jet, origin='lower') im2 = plt.figimage(Z, xo=100, yo=100, alpha=.8, cmap=cm.jet, origin='lower') - -if 0: - dpi = 72 - plt.savefig('figimage_%d.png'%dpi, dpi=dpi, facecolor='gray') - plt.savefig('figimage_%d.pdf'%dpi, dpi=dpi, facecolor='gray') - plt.savefig('figimage_%d.svg'%dpi, dpi=dpi, facecolor='gray') - plt.savefig('figimage_%d.eps'%dpi, dpi=dpi, facecolor='gray') plt.show() Modified: trunk/matplotlib/lib/matplotlib/artist.py =================================================================== --- trunk/matplotlib/lib/matplotlib/artist.py 2010-06-04 02:40:00 UTC (rev 8371) +++ trunk/matplotlib/lib/matplotlib/artist.py 2010-06-04 03:37:56 UTC (rev 8372) @@ -78,7 +78,7 @@ self._transformSet = False self._visible = True self._animated = False - self._alpha = 1.0 + self._alpha = None self.clipbox = None self._clippath = None self._clipon = True Modified: trunk/matplotlib/lib/matplotlib/axes.py =================================================================== --- trunk/matplotlib/lib/matplotlib/axes.py 2010-06-04 02:40:00 UTC (rev 8371) +++ trunk/matplotlib/lib/matplotlib/axes.py 2010-06-04 03:37:56 UTC (rev 8372) @@ -372,7 +372,7 @@ Keyword Description ================ ========================================= *adjustable* [ 'box' | 'datalim' | 'box-forced'] - *alpha* float: the alpha transparency + *alpha* float: the alpha transparency (can be None) *anchor* [ 'C', 'SW', 'S', 'SE', 'E', 'NE', 'N', 'NW', 'W' ] *aspect* [ 'auto' | 'equal' | aspect_ratio ] @@ -5338,14 +5338,14 @@ @docstring.dedent_interpd def scatter(self, x, y, s=20, c='b', marker='o', cmap=None, norm=None, - vmin=None, vmax=None, alpha=1.0, linewidths=None, + vmin=None, vmax=None, alpha=None, linewidths=None, faceted=True, verts=None, **kwargs): """ call signatures:: scatter(x, y, s=20, c='b', marker='o', cmap=None, norm=None, - vmin=None, vmax=None, alpha=1.0, linewidths=None, + vmin=None, vmax=None, alpha=None, linewidths=None, verts=None, **kwargs) Make a scatter plot of *x* versus *y*, where *x*, *y* are @@ -5438,7 +5438,7 @@ *norm* instance, your settings for *vmin* and *vmax* will be ignored. - *alpha*: 0 <= scalar <= 1 + *alpha*: 0 <= scalar <= 1 or None The alpha value for the patches *linewidths*: [ None | scalar | sequence ] @@ -5656,7 +5656,7 @@ def hexbin(self, x, y, C = None, gridsize = 100, bins = None, xscale = 'linear', yscale = 'linear', extent = None, cmap=None, norm=None, vmin=None, vmax=None, - alpha=1.0, linewidths=None, edgecolors='none', + alpha=None, linewidths=None, edgecolors='none', reduce_C_function = np.mean, mincnt=None, marginals=False, **kwargs): """ @@ -5665,7 +5665,7 @@ hexbin(x, y, C = None, gridsize = 100, bins = None, xscale = 'linear', yscale = 'linear', cmap=None, norm=None, vmin=None, vmax=None, - alpha=1.0, linewidths=None, edgecolors='none' + alpha=None, linewidths=None, edgecolors='none' reduce_C_function = np.mean, mincnt=None, marginals=True **kwargs) @@ -5744,7 +5744,7 @@ array *C* is used. Note if you pass a norm instance, your settings for *vmin* and *vmax* will be ignored. - *alpha*: scalar + *alpha*: scalar between 0 and 1, or None the alpha value for the patches *linewidths*: [ None | scalar ] @@ -6438,14 +6438,14 @@ @docstring.dedent_interpd def imshow(self, X, cmap=None, norm=None, aspect=None, - interpolation=None, alpha=1.0, vmin=None, vmax=None, + interpolation=None, alpha=None, vmin=None, vmax=None, origin=None, extent=None, shape=None, filternorm=1, filterrad=4.0, imlim=None, resample=None, url=None, **kwargs): """ call signature:: imshow(X, cmap=None, norm=None, aspect=None, interpolation=None, - alpha=1.0, vmin=None, vmax=None, origin=None, extent=None, + alpha=None, vmin=None, vmax=None, origin=None, extent=None, **kwargs) Display the image in *X* to current axes. *X* may be a float @@ -6505,6 +6505,7 @@ *alpha*: scalar The alpha blending value, between 0 (transparent) and 1 (opaque) + or *None* *origin*: [ None | 'upper' | 'lower' ] Place the [0,0] index of the array in the upper left or lower left @@ -6673,7 +6674,7 @@ An mpl color or sequence of colors will set the edge color - *alpha*: 0 <= scalar <= 1 + *alpha*: 0 <= scalar <= 1 or *None* the alpha blending value Return value is a :class:`matplotlib.collection.Collection` @@ -6729,7 +6730,7 @@ if not self._hold: self.cla() - alpha = kwargs.pop('alpha', 1.0) + alpha = kwargs.pop('alpha', None) norm = kwargs.pop('norm', None) cmap = kwargs.pop('cmap', None) vmin = kwargs.pop('vmin', None) @@ -6858,7 +6859,7 @@ An mpl color or sequence of colors will set the edge color - *alpha*: 0 <= scalar <= 1 + *alpha*: 0 <= scalar <= 1 or *None* the alpha blending value Return value is a :class:`matplotlib.collection.QuadMesh` @@ -6878,7 +6879,7 @@ """ if not self._hold: self.cla() - alpha = kwargs.pop('alpha', 1.0) + alpha = kwargs.pop('alpha', None) norm = kwargs.pop('norm', None) cmap = kwargs.pop('cmap', None) vmin = kwargs.pop('vmin', None) @@ -7003,7 +7004,7 @@ luminance data. If either are *None*, the min and max of the color array *C* is used. If you pass a norm instance, *vmin* and *vmax* will be *None*. - *alpha*: 0 <= scalar <= 1 + *alpha*: 0 <= scalar <= 1 or *None* the alpha blending value Return value is an image if a regular or rectangular grid @@ -7014,7 +7015,7 @@ if not self._hold: self.cla() - alpha = kwargs.pop('alpha', 1.0) + alpha = kwargs.pop('alpha', None) norm = kwargs.pop('norm', None) cmap = kwargs.pop('cmap', None) vmin = kwargs.pop('vmin', None) Modified: trunk/matplotlib/lib/matplotlib/backend_bases.py =================================================================== --- trunk/matplotlib/lib/matplotlib/backend_bases.py 2010-06-04 02:40:00 UTC (rev 8371) +++ trunk/matplotlib/lib/matplotlib/backend_bases.py 2010-06-04 03:37:56 UTC (rev 8372) @@ -727,6 +727,8 @@ Set the alpha value used for blending - not supported on all backends """ + if alpha is None: + alpha = 1.0 self._alpha = alpha def set_antialiased(self, b): Modified: trunk/matplotlib/lib/matplotlib/cm.py =================================================================== --- trunk/matplotlib/lib/matplotlib/cm.py 2010-06-04 02:40:00 UTC (rev 8371) +++ trunk/matplotlib/lib/matplotlib/cm.py 2010-06-04 03:37:56 UTC (rev 8372) @@ -160,21 +160,25 @@ 'set the colorbar image and axes associated with mappable' self.colorbar = im, ax - def to_rgba(self, x, alpha=1.0, bytes=False): + def to_rgba(self, x, alpha=None, bytes=False): '''Return a normalized rgba array corresponding to *x*. If *x* is already an rgb array, insert *alpha*; if it is already rgba, return it unchanged. If *bytes* is True, return rgba as 4 uint8s instead of 4 floats. ''' + if alpha is None: + _alpha = 1.0 + else: + _alpha = alpha try: if x.ndim == 3: if x.shape[2] == 3: if x.dtype == np.uint8: - alpha = np.array(alpha*255, np.uint8) + _alpha = np.array(_alpha*255, np.uint8) m, n = x.shape[:2] xx = np.empty(shape=(m,n,4), dtype = x.dtype) xx[:,:,:3] = x - xx[:,:,3] = alpha + xx[:,:,3] = _alpha elif x.shape[2] == 4: xx = x else: Modified: trunk/matplotlib/lib/matplotlib/collections.py =================================================================== --- trunk/matplotlib/lib/matplotlib/collections.py 2010-06-04 02:40:00 UTC (rev 8371) +++ trunk/matplotlib/lib/matplotlib/collections.py 2010-06-04 03:37:56 UTC (rev 8372) @@ -443,25 +443,27 @@ def set_alpha(self, alpha): """ Set the alpha tranparencies of the collection. *alpha* must be - a float. + a float or *None*. - ACCEPTS: float + ACCEPTS: float or None """ - try: float(alpha) - except TypeError: raise TypeError('alpha must be a float') - else: - artist.Artist.set_alpha(self, alpha) + if alpha is not None: try: - self._facecolors = mcolors.colorConverter.to_rgba_array( - self._facecolors_original, self._alpha) - except (AttributeError, TypeError, IndexError): - pass - try: - if self._edgecolors_original != 'face': - self._edgecolors = mcolors.colorConverter.to_rgba_array( - self._edgecolors_original, self._alpha) - except (AttributeError, TypeError, IndexError): - pass + float(alpha) + except TypeError: + raise TypeError('alpha must be a float or None') + artist.Artist.set_alpha(self, alpha) + try: + self._facecolors = mcolors.colorConverter.to_rgba_array( + self._facecolors_original, self._alpha) + except (AttributeError, TypeError, IndexError): + pass + try: + if self._edgecolors_original != 'face': + self._edgecolors = mcolors.colorConverter.to_rgba_array( + self._edgecolors_original, self._alpha) + except (AttributeError, TypeError, IndexError): + pass def get_linewidths(self): return self._linewidths Modified: trunk/matplotlib/lib/matplotlib/colorbar.py =================================================================== --- trunk/matplotlib/lib/matplotlib/colorbar.py 2010-06-04 02:40:00 UTC (rev 8371) +++ trunk/matplotlib/lib/matplotlib/colorbar.py 2010-06-04 03:37:56 UTC (rev 8372) @@ -197,7 +197,7 @@ def __init__(self, ax, cmap=None, norm=None, - alpha=1.0, + alpha=None, values=None, boundaries=None, orientation='vertical', Modified: trunk/matplotlib/lib/matplotlib/contour.py =================================================================== --- trunk/matplotlib/lib/matplotlib/contour.py 2010-06-04 02:40:00 UTC (rev 8371) +++ trunk/matplotlib/lib/matplotlib/contour.py 2010-06-04 03:37:56 UTC (rev 8372) @@ -655,7 +655,7 @@ self.linewidths = kwargs.get('linewidths', None) self.linestyles = kwargs.get('linestyles', None) - self.alpha = kwargs.get('alpha', 1.0) + self.alpha = kwargs.get('alpha', None) self.origin = kwargs.get('origin', None) self.extent = kwargs.get('extent', None) cmap = kwargs.get('cmap', None) Modified: trunk/matplotlib/lib/matplotlib/figure.py =================================================================== --- trunk/matplotlib/lib/matplotlib/figure.py 2010-06-04 02:40:00 UTC (rev 8371) +++ trunk/matplotlib/lib/matplotlib/figure.py 2010-06-04 03:37:56 UTC (rev 8372) @@ -340,7 +340,7 @@ def figimage(self, X, xo=0, yo=0, - alpha=1.0, + alpha=None, norm=None, cmap=None, vmin=None, @@ -380,7 +380,7 @@ None, the min and max of the luminance values will be used. Note if you pass a norm instance, the settings for *vmin* and *vmax* will be ignored. - alpha the alpha blending value, default is 1.0 + alpha the alpha blending value, default is None origin [ 'upper' | 'lower' ] Indicates where the [0,0] index of the array is in the upper left or lower left corner of the axes. Defaults to the rc image.origin value Modified: trunk/matplotlib/lib/matplotlib/text.py =================================================================== --- trunk/matplotlib/lib/matplotlib/text.py 2010-06-04 02:40:00 UTC (rev 8371) +++ trunk/matplotlib/lib/matplotlib/text.py 2010-06-04 03:37:56 UTC (rev 8372) @@ -61,7 +61,7 @@ ========================== ========================================================================= Property Value ========================== ========================================================================= - alpha float + alpha float or None animated [True | False] backgroundcolor any matplotlib color bbox rectangle prop dict plus key 'pad' which is a pad in points This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ ThinkGeek and WIRED's GeekDad team up for the Ultimate GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the lucky parental unit. See the prize list and enter to win: http://p.sf.net/sfu/thinkgeek-promo _______________________________________________ Matplotlib-checkins mailing list Matplotlib-checkins@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-checkins