Skip to content

Mplot3d/collection cmap fix #762

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

Merged
Merged
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
Fix scatter3d bug
* Found a simple solution to the "colors disappear after interacting with
  a scatter3d plot" bug. Should close #761 and close #152.
  • Loading branch information
WeatherGod committed Mar 13, 2012
commit aa5bdbed2c586b580840ec35d20e67aabb67f2d6
13 changes: 12 additions & 1 deletion lib/mpl_toolkits/mplot3d/art3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ def do_3d_projection(self, renderer):
segments_2d = [zip(xs, ys) for (xs, ys, zs) in xyslist]
LineCollection.set_segments(self, segments_2d)

# FIXME
minz = 1e9
for (xs, ys, zs) in xyslist:
minz = min(minz, min(zs))
Expand Down Expand Up @@ -300,6 +301,9 @@ def set_sort_zpos(self,val):
self._sort_zpos = val

def set_3d_properties(self, zs, zdir):
# Force the collection to initialize the face and edgecolors
# just in case it is a scalarmappable with a colormap.
self.update_scalarmappable()
offsets = self.get_offsets()
if len(offsets) > 0:
xs, ys = zip(*self.get_offsets())
Expand Down Expand Up @@ -416,6 +420,9 @@ def set_verts(self, verts, closed=True):
PolyCollection.set_verts(self, [], closed)

def set_3d_properties(self):
# Force the collection to initialize the face and edgecolors
# just in case it is a scalarmappable with a colormap.
self.update_scalarmappable()
self._sort_zpos = None
self.set_zsort(True)
self._facecolors3d = PolyCollection.get_facecolors(self)
Expand All @@ -429,7 +436,7 @@ def do_3d_projection(self, renderer):
'''
Perform the 3D projection for this object.
'''

# FIXME: This may no longer be needed?
if self._A is not None:
self.update_scalarmappable()
self._facecolors3d = self._facecolors
Expand Down Expand Up @@ -572,6 +579,10 @@ def get_colors(c, num):

def zalpha(colors, zs):
"""Modify the alphas of the color list according to depth"""
# FIXME: This only works well if the points for *zs* are well-spaced
# in all three dimensions. Otherwise, at certain orientations,
# the min and max zs are very close together.
# Should really normalize against the viewing depth.
colors = get_colors(colors, len(zs))
if zs.size > 0 :
norm = Normalize(min(zs), max(zs))
Expand Down