Skip to content

Traitlets #4762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 73 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
c202812
supress ipynb files
rmorshea Aug 6, 2015
9d4092e
todo list
rmorshea Jul 20, 2015
0edf017
refactoring with new workflow
rmorshea Jul 21, 2015
f73f7b6
transform refactoring : see TODO
rmorshea Jul 23, 2015
8b91ade
transform refactoring : see TODO
rmorshea Jul 23, 2015
ff69573
revert .gitignore
rmorshea Jul 23, 2015
602ce41
remove ipynb_checkpoints
rmorshea Jul 23, 2015
97167ac
see TODO
rmorshea Jul 23, 2015
52fdc79
see TODO
rmorshea Jul 23, 2015
de152bc
see TODO
rmorshea Jul 23, 2015
ae5b5ba
transform implamented
rmorshea Jul 30, 2015
5f58d90
progress update
rmorshea Jul 30, 2015
a8a1f18
see TODO
rmorshea Aug 1, 2015
664c02a
last update of refactor
rmorshea Aug 1, 2015
0275157
ignore refactor
rmorshea Aug 1, 2015
e258cd2
last update to refactor
rmorshea Aug 1, 2015
a14f83b
comment change
rmorshea Aug 2, 2015
e238441
rebase with origin/master (up to date with upstream/master)
rmorshea Aug 2, 2015
97f0532
add figure traitlet
rmorshea Aug 5, 2015
e1d976d
shrink file
rmorshea Aug 5, 2015
d85e2c1
progress towards full test suite pass
rmorshea Aug 14, 2015
b6d3e45
errors reduced to pickling and ref counts
rmorshea Aug 14, 2015
be7f591
update rebase
rmorshea Aug 14, 2015
5609b44
fix memory leak in Artist
rmorshea Aug 14, 2015
871388d
fix memory leaks in test_quiver.py
rmorshea Aug 14, 2015
4030397
fix exdict inheritance
rmorshea Aug 15, 2015
5a2160f
fix pickling
rmorshea Aug 15, 2015
b436bee
update traitlets
rmorshea Aug 15, 2015
593e34c
remove print statement
rmorshea Aug 15, 2015
4b6195c
resolve pickling
rmorshea Aug 16, 2015
d11236c
update exdict
rmorshea Aug 16, 2015
1debbd0
simple performance test
rmorshea Aug 16, 2015
bbf1c89
update TODO progress report
rmorshea Aug 16, 2015
709bdac
refactor visible and animated
rmorshea Aug 17, 2015
867899c
shrink file
rmorshea Aug 17, 2015
cfb0713
refactor alpha, but failed alpha blending in agg
rmorshea Aug 17, 2015
e9c8489
refactor rasterize, pickable, evenston
rmorshea Aug 18, 2015
a2e6676
update rebase
rmorshea Aug 18, 2015
299ceb2
FIX: revert changes to gc calls
tacaswell Aug 18, 2015
93945ab
fix memory leak
rmorshea Aug 18, 2015
9934482
see TODO
rmorshea Aug 21, 2015
22e4b0c
change property updates via name
rmorshea Aug 23, 2015
9b65ee0
see TODO
rmorshea Aug 25, 2015
9528a83
base artist refactor complete: see TODO
rmorshea Aug 25, 2015
f69490b
fix sketch_params/path_effects default
rmorshea Aug 25, 2015
afddefe
fix setp/getp, change forced callbacks
rmorshea Aug 25, 2015
cd1d60a
reintroduce traitlets test
rmorshea Aug 26, 2015
89caa0f
fix typo
rmorshea Sep 8, 2015
7717e07
update rebased commits
rmorshea Sep 8, 2015
57131b2
add traitlets as test dep
rmorshea Sep 8, 2015
6aacb91
simplify old value store for forced callbacks
rmorshea Sep 9, 2015
4cf88ff
use new traitlets api (has quiver memory leaks)
rmorshea Sep 16, 2015
bb02b38
add @retrieve decorator
rmorshea Sep 18, 2015
a43cdf9
correct private get
rmorshea Oct 2, 2015
be3de2f
now requires most revent version of traitlets
rmorshea Oct 5, 2015
340df20
reintroduce mute context manager, and begin uncommenting legacy sette…
rmorshea Oct 6, 2015
84ac0ff
edit traitlets as test dep
rmorshea Oct 6, 2015
7dc256a
finish uncommenting setters/getters
rmorshea Oct 8, 2015
d895089
MNT: minor fixes
tacaswell Oct 8, 2015
6ba2c89
TST: use bleeding edge branch for traitlets
tacaswell Oct 8, 2015
0064153
pep8 fixes
rmorshea Oct 9, 2015
ffe9d09
final pep8 fixes
rmorshea Oct 9, 2015
bdf6622
traitlet warning supression
rmorshea Oct 9, 2015
08a6db7
fix pylab example
rmorshea Oct 12, 2015
0d936ed
supress more warnings
rmorshea Oct 14, 2015
9d76e5a
supress more warnings
rmorshea Oct 14, 2015
3826b49
correct impropper validate usage
rmorshea Nov 2, 2015
abba50b
correct after rebase
rmorshea Nov 20, 2015
d8f65db
setattr in SimpleChainedObjects
rmorshea Nov 22, 2015
1917a2d
fix travis.yml after rebase
rmorshea Nov 22, 2015
86a9b69
misc edits, mark as changed only if setter is used
rmorshea Nov 23, 2015
40d5b49
change traitlets warn message
rmorshea Dec 2, 2015
0d1eb25
COMPRESS
rmorshea Mar 9, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor alpha, but failed alpha blending in agg
  • Loading branch information
rmorshea committed Nov 27, 2015
commit cfb0713da4f413f37f3ea69a628c7dacdd7a1b56
52 changes: 34 additions & 18 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .path import Path

from .traitlets import (Instance, Configurable, gTransformInstance, Bool, Undefined,
BaseDescriptor, getargspec, PrivateMethodMixin)
BaseDescriptor, getargspec, PrivateMethodMixin, Float, TraitError)

# Note, matplotlib artists use the doc strings for set and get
# methods to enable the introspection methods of setp and getp. Every
Expand Down Expand Up @@ -146,6 +146,20 @@ def _animated_changed(self, name, new):
self.pchanged()
self.stale = True

# Float defaults to 0.0, must have None arg
alpha = Float(None, allow_none=True)

def _alpha_validate(self, value, trait):
if 0>value>1:
msg = ("The '%s' trait of %s instance can only be"
"transparent (0.0) through opaque (1.0)")
raise TraitError(msg % (trait.name, self.__class__))
return value

def _alpha_changed(self, name, new):
self.pchanged()
self.stale = True

def __init__(self):
# self._stale = True
# self._axes = None
Expand All @@ -157,7 +171,7 @@ def __init__(self):

# self._visible = True
# self._animated = False
self._alpha = None
# self._alpha = None
self.clipbox = None
self._clippath = None
self._clipon = True
Expand Down Expand Up @@ -765,12 +779,13 @@ def set_clip_path(self, path, transform=None):
self.pchanged()
self.stale = True

def get_alpha(self):
"""
Return the alpha value used for blending - not supported on all
backends
"""
return self._alpha
#!DEPRECATED
# def get_alpha(self):
# """
# Return the alpha value used for blending - not supported on all
# backends
# """
# return self._alpha

#!DEPRECATED
# def get_visible(self):
Expand Down Expand Up @@ -864,16 +879,17 @@ def draw(self, renderer, *args, **kwargs):
return
self.stale = False

def set_alpha(self, alpha):
"""
Set the alpha value used for blending - not supported on
all backends.
#!DEPRECATED
# def set_alpha(self, alpha):
# """
# Set the alpha value used for blending - not supported on
# all backends.

ACCEPTS: float (0.0 transparent through 1.0 opaque)
"""
self._alpha = alpha
self.pchanged()
self.stale = True
# ACCEPTS: float (0.0 transparent through 1.0 opaque)
# """
# self._alpha = alpha
# self.pchanged()
# self.stale = True

#!DEPRECATED
# def set_visible(self, b):
Expand Down Expand Up @@ -966,7 +982,7 @@ def update_from(self, other):
self.private('transform', other.private('transform'))
self.transform_set = other.transform_set
self.private('visible', other.private('visible'))
self._alpha = other._alpha
self.private('alpha',other.alpha)
self.clipbox = other.clipbox
self._clipon = other._clipon
self._clippath = other._clippath
Expand Down
16 changes: 8 additions & 8 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4269,7 +4269,7 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
collection.set_array(accum)
collection.set_cmap(cmap)
collection.set_norm(norm)
collection.set_alpha(alpha)
collection.alpha = alpha
collection.update(kwargs)

if vmin is not None or vmax is not None:
Expand Down Expand Up @@ -4330,7 +4330,7 @@ def coarse_bin(x, y, coarse):
hbar.set_array(values)
hbar.set_cmap(cmap)
hbar.set_norm(norm)
hbar.set_alpha(alpha)
hbar.alpha = alpha
hbar.update(kwargs)
self.add_collection(hbar, autolim=False)

Expand Down Expand Up @@ -4358,7 +4358,7 @@ def coarse_bin(x, y, coarse):
vbar.set_array(values)
vbar.set_cmap(cmap)
vbar.set_norm(norm)
vbar.set_alpha(alpha)
vbar.alpha = alpha
vbar.update(kwargs)
self.add_collection(vbar, autolim=False)

Expand Down Expand Up @@ -4940,7 +4940,7 @@ def imshow(self, X, cmap=None, norm=None, aspect=None,
resample=resample, **kwargs)

im.set_data(X)
im.set_alpha(alpha)
im.alpha = alpha
if im.get_clip_path() is None:
# image does not already have clipping set, clip to axes patch
im.set_clip_path(self.patch)
Expand Down Expand Up @@ -5258,7 +5258,7 @@ def pcolor(self, *args, **kwargs):

collection = mcoll.PolyCollection(verts, **kwargs)

collection.set_alpha(alpha)
collection.alpha = alpha
collection.set_array(C)
if norm is not None and not isinstance(norm, mcolors.Normalize):
msg = "'norm' must be an instance of 'mcolors.Normalize'"
Expand Down Expand Up @@ -5409,7 +5409,7 @@ def pcolormesh(self, *args, **kwargs):
collection = mcoll.QuadMesh(
Nx - 1, Ny - 1, coords,
antialiased=antialiased, shading=shading, **kwargs)
collection.set_alpha(alpha)
collection.alpha = alpha
collection.set_array(C)
if norm is not None and not isinstance(norm, mcolors.Normalize):
msg = "'norm' must be an instance of 'mcolors.Normalize'"
Expand Down Expand Up @@ -5593,7 +5593,7 @@ def pcolorfast(self, *args, **kwargs):
# handle relevant superclass kwargs; the initializer
# should do much more than it does now.
collection = mcoll.QuadMesh(nc, nr, coords, 0, edgecolors="None")
collection.set_alpha(alpha)
collection.alpha = alpha
collection.set_array(C)
collection.set_cmap(cmap)
collection.set_norm(norm)
Expand All @@ -5612,7 +5612,7 @@ def pcolorfast(self, *args, **kwargs):
extent=(xl, xr, yb, yt),
**kwargs)
im.set_data(C)
im.set_alpha(alpha)
im.alpha = alpha
self.add_image(im)
ret = im

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2313,7 +2313,7 @@ def draw(self, renderer=None, inframe=False):
zorder_images.sort(key=lambda x: x[0])

mag = renderer.get_image_magnification()
ims = [(im.make_image(mag), 0, 0, im.get_alpha())
ims = [(im.make_image(mag), 0, 0, im.alpha)
for z, im in zorder_images]

l, b, r, t = self.bbox.extents
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_nbagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def closer(event):

canvas = FigureCanvasNbAgg(figure)
if rcParams['nbagg.transparent']:
figure.patch.set_alpha(0)
figure.patch.alpha = 0
manager = FigureManagerNbAgg(canvas, num)

if is_interactive():
Expand Down
54 changes: 36 additions & 18 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def set_facecolor(self, c):
if c is None:
c = mpl.rcParams['patch.facecolor']
self._facecolors_original = c
self._facecolors = mcolors.colorConverter.to_rgba_array(c, self._alpha)
self._facecolors = mcolors.colorConverter.to_rgba_array(c, self.alpha)
self.stale = True

def set_facecolors(self, c):
Expand Down Expand Up @@ -657,39 +657,57 @@ def set_edgecolor(self, c):
if c is None:
c = mpl.rcParams['patch.edgecolor']
self._edgecolors_original = c
self._edgecolors = mcolors.colorConverter.to_rgba_array(c, self._alpha)
self._edgecolors = mcolors.colorConverter.to_rgba_array(c, self.alpha)
self.stale = True

def set_edgecolors(self, c):
"""alias for set_edgecolor"""
return self.set_edgecolor(c)

def set_alpha(self, alpha):
"""
Set the alpha tranparencies of the collection. *alpha* must be
a float or *None*.
def _alpha_validate(self, value, trait):
value = artist.Artist._alpha_validate(self, value, trait)

ACCEPTS: float or None
"""
if alpha is not None:
try:
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)
self._facecolors_original, value)
except (AttributeError, TypeError, IndexError):
pass
try:
if (not isinstance(self._edgecolors_original, six.string_types)
or self._edgecolors_original != str('face')):
self._edgecolors = mcolors.colorConverter.to_rgba_array(
self._edgecolors_original, self._alpha)
self._edgecolors_original, value)
except (AttributeError, TypeError, IndexError):
pass

return value

#!DEPRECATED
# def set_alpha(self, alpha):
# """
# Set the alpha tranparencies of the collection. *alpha* must be
# a float or *None*.

# ACCEPTS: float or None
# """
# if alpha is not None:
# try:
# 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 != str('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
get_linewidth = get_linewidths
Expand All @@ -710,9 +728,9 @@ def update_scalarmappable(self):
if not self.check_update("array"):
return
if self._is_filled:
self._facecolors = self.to_rgba(self._A, self._alpha)
self._facecolors = self.to_rgba(self._A, self.alpha)
elif self._is_stroked:
self._edgecolors = self.to_rgba(self._A, self._alpha)
self._edgecolors = self.to_rgba(self._A, self.alpha)
self.stale = True

def get_fill(self):
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -885,7 +885,7 @@ def __init__(self, ax, mappable, **kw):

if isinstance(mappable, contour.ContourSet):
CS = mappable
kw['alpha'] = mappable.get_alpha()
kw['alpha'] = mappable.alpha
kw['boundaries'] = CS._levels
kw['values'] = CS.cvalues
kw['extend'] = CS.extend
Expand All @@ -900,7 +900,7 @@ def __init__(self, ax, mappable, **kw):
kw.setdefault('extend', cmap.colorbar_extend)

if isinstance(mappable, martist.Artist):
kw['alpha'] = mappable.get_alpha()
kw['alpha'] = mappable.alpha

ColorbarBase.__init__(self, ax, **kw)

Expand Down Expand Up @@ -972,7 +972,7 @@ def update_bruteforce(self, mappable):
self.solids = None
self.lines = list()
self.dividers = None
self.set_alpha(mappable.get_alpha())
self.set_alpha(mappable.alpha)
self.cmap = mappable.cmap
self.norm = mappable.norm
self.config_axis()
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -1018,7 +1018,7 @@ def legend_elements(self, variable_name='x', str_format=str):
(0, 0), 1, 1,
facecolor=collection.get_facecolor()[0],
hatch=collection.get_hatch(),
alpha=collection.get_alpha())
alpha=collection.alpha)
artists.append(patch)

lower = str_format(lower)
Expand Down Expand Up @@ -1135,7 +1135,7 @@ def changed(self):
else:
collection.set_color(color)
for label, cv in zip(self.labelTexts, self.labelCValues):
label.set_alpha(self.alpha)
label.alpha = self.alpha
label.set_color(self.labelMappable.to_rgba(cv))
# add label colors
cm.ScalarMappable.changed(self)
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ def figimage(self, X,
im.stale_callback = _stale_figure_callback

im.set_array(X)
im.set_alpha(alpha)
im.alpha = alpha
if norm is None:
im.set_clim(vmin, vmax)
self.images.append(im)
Expand Down Expand Up @@ -1229,7 +1229,7 @@ def draw(self, renderer):
# make a composite image blending alpha
# list of (_image.Image, ox, oy)
mag = renderer.get_image_magnification()
ims = [(im.make_image(mag), im.ox, im.oy, im.get_alpha())
ims = [(im.make_image(mag), im.ox, im.oy, im.alpha)
for im in self.images]

im = _image.from_images(int(self.bbox.height * mag),
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/finance.py
Original file line number Diff line number Diff line change
Expand Up @@ -805,7 +805,7 @@ def _candlestick(ax, quotes, width=0.2, colorup='k', colordown='r',
facecolor=color,
edgecolor=color,
)
rect.set_alpha(alpha)
rect.alpha = alpha

lines.append(vline)
patches.append(rect)
Expand Down
Loading