8000 [SPRINT] Much better alpha control in mplot3d. Closes #1541 by WeatherGod · Pull Request #2169 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

[SPRINT] Much better alpha control in mplot3d. Closes #1541 #2169

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
Changes from all commits
Commits
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
Much better alpha control in mplot3d. Closes #1541
Probably haven't solved them all, but this gets most of them.
  • Loading branch information
WeatherGod committed Jun 28, 2013
commit b83977f46806b35e258413db63618b58e2ef0d02
36 changes: 33 additions & 3 deletions lib/mpl_toolkits/mplot3d/art3d.py
Original file line number Diff line number Diff line change
8000 Expand Up @@ -9,6 +9,7 @@
'''

from matplotlib import lines, text as mtext, path as mpath, colors as mcolors
from matplotlib import artist
from matplotlib.collections import Collection, LineCollection, \
PolyCollection, PatchCollection
from matplotlib.cm import ScalarMappable
Expand Down Expand Up @@ -318,9 +319,13 @@ def do_3d_projection(self, renderer):
xs, ys, zs = self._offsets3d
vxs, vys, vzs, vis = proj3d.proj_transform_clip(xs, ys, zs, renderer.M)
#FIXME: mpl allows us no way to unset the collection alpha value
self._alpha = None
self.set_facecolors(zalpha(self._facecolor3d, vzs))
self.set_edgecolors(zalpha(self._edgecolor3d, vzs))
#self._alpha = None
fcs = mcolors.colorConverter.to_rgba_array(self._facecolor3d,
self._alpha)
mcs = mcolors.colorConverter.to_rgba_array(self._edgecolor3d,
self._alpha)
self.set_facecolors(zalpha(fcs, vzs))
self.set_edgecolors(zalpha(mcs, vzs))
PatchCollection.set_offsets(self, zip(vxs, vys))

if vzs.size > 0 :
Expand Down Expand Up @@ -427,6 +432,7 @@ def set_3d_properties(self):
self.set_zsort(True)
self._facecolors3d = PolyCollection.get_facecolors(self)
self._edgecolors3d = PolyCollection.get_edgecolors(self)
self._alpha3d = PolyCollection.get_alpha(self)

def set_sort_zpos(self,val):
'''Set the position to use for z-sorting.'''
Expand Down Expand Up @@ -495,6 +501,30 @@ def set_edgecolor(self, colors):
self._edgecolors3d = PolyCollection.get_edgecolor(self)
set_edgecolors = set_edgecolor

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._facecolors3d, self._alpha)
except (AttributeError, TypeError, IndexError):
pass
try:
self._edgecolors = mcolors.colorConverter.to_rgba_array(
self._edgecolors3d, self._alpha)
except (AttributeError, TypeError, IndexError):
pass

def get_facecolors(self):
return self._facecolors2d
get_facecolor = get_facecolors
Expand Down
0