|
14 | 14 | from six.moves import zip |
15 | 15 |
|
16 | 16 | from matplotlib import lines, text as mtext, path as mpath, colors as mcolors |
| 17 | +from matplotlib import artist |
17 | 18 | from matplotlib.collections import Collection, LineCollection, \ |
18 | 19 | PolyCollection, PatchCollection, PathCollection |
19 | 20 | from matplotlib.cm import ScalarMappable |
@@ -340,9 +341,13 @@ def do_3d_projection(self, renderer): |
340 | 341 | xs, ys, zs = self._offsets3d |
341 | 342 | vxs, vys, vzs, vis = proj3d.proj_transform_clip(xs, ys, zs, renderer.M) |
342 | 343 | #FIXME: mpl allows us no way to unset the collection alpha value |
343 | | - self._alpha = None |
344 | | - self.set_facecolors(zalpha(self._facecolor3d, vzs)) |
345 | | - self.set_edgecolors(zalpha(self._edgecolor3d, vzs)) |
| 344 | + #self._alpha = None |
| 345 | + fcs = mcolors.colorConverter.to_rgba_array(self._facecolor3d, |
| 346 | + self._alpha) |
| 347 | + mcs = mcolors.colorConverter.to_rgba_array(self._edgecolor3d, |
| 348 | + self._alpha) |
| 349 | + self.set_facecolors(zalpha(fcs, vzs)) |
| 350 | + self.set_edgecolors(zalpha(mcs, vzs)) |
346 | 351 | super(self.__class__, self).set_offsets(list(zip(vxs, vys))) |
347 | 352 |
|
348 | 353 | if vzs.size > 0 : |
@@ -461,6 +466,7 @@ def set_3d_properties(self): |
461 | 466 | self.set_zsort(True) |
462 | 467 | self._facecolors3d = PolyCollection.get_facecolors(self) |
463 | 468 | self._edgecolors3d = PolyCollection.get_edgecolors(self) |
| 469 | + self._alpha3d = PolyCollection.get_alpha(self) |
464 | 470 |
|
465 | 471 | def set_sort_zpos(self,val): |
466 | 472 | '''Set the position to use for z-sorting.''' |
@@ -529,6 +535,30 @@ def set_edgecolor(self, colors): |
529 | 535 | self._edgecolors3d = PolyCollection.get_edgecolor(self) |
530 | 536 | set_edgecolors = set_edgecolor |
531 | 537 |
|
| 538 | + def set_alpha(self, alpha): |
| 539 | + """ |
| 540 | + Set the alpha tranparencies of the collection. *alpha* must be |
| 541 | + a float or *None*. |
| 542 | +
|
| 543 | + ACCEPTS: float or None |
| 544 | + """ |
| 545 | + if alpha is not None: |
| 546 | + try: |
| 547 | + float(alpha) |
| 548 | + except TypeError: |
| 549 | + raise TypeError('alpha must be a float or None') |
| 550 | + artist.Artist.set_alpha(self, alpha) |
| 551 | + try: |
| 552 | + self._facecolors = mcolors.colorConverter.to_rgba_array( |
| 553 | + self._facecolors3d, self._alpha) |
| 554 | + except (AttributeError, TypeError, IndexError): |
| 555 | + pass |
| 556 | + try: |
| 557 | + self._edgecolors = mcolors.colorConverter.to_rgba_array( |
| 558 | + self._edgecolors3d, self._alpha) |
| 559 | + except (AttributeError, TypeError, IndexError): |
| 560 | + pass |
| 561 | + |
532 | 562 | def get_facecolors(self): |
533 | 563 | return self._facecolors2d |
534 | 564 | get_facecolor = get_facecolors |
|
0 commit comments