Modify the alpha values of the color list according to z-depth.
(
colors,
zs,
min_alpha=0.3,
_data_scale=None,
)
| 1607 | |
| 1608 | |
| 1609 | def _zalpha( |
| 1610 | colors, |
| 1611 | zs, |
| 1612 | min_alpha=0.3, |
| 1613 | _data_scale=None, |
| 1614 | ): |
| 1615 | """Modify the alpha values of the color list according to z-depth.""" |
| 1616 | |
| 1617 | if len(colors) == 0 or len(zs) == 0: |
| 1618 | return np.zeros((0, 4)) |
| 1619 | |
| 1620 | # Alpha values beyond the range 0-1 inclusive make no sense, so clip them |
| 1621 | min_alpha = np.clip(min_alpha, 0, 1) |
| 1622 | |
| 1623 | if _data_scale is None or _data_scale == 0: |
| 1624 | # Don't scale the alpha values since we have no valid data scale for reference |
| 1625 | sats = np.ones_like(zs) |
| 1626 | |
| 1627 | else: |
| 1628 | # Deeper points have an increasingly transparent appearance |
| 1629 | sats = np.clip(1 - (zs - np.min(zs)) / _data_scale, min_alpha, 1) |
| 1630 | |
| 1631 | rgba = np.broadcast_to(mcolors.to_rgba_array(colors), (len(zs), 4)) |
| 1632 | |
| 1633 | # Change the alpha values of the colors using the generated alpha multipliers |
| 1634 | return np.column_stack([rgba[:, :3], rgba[:, 3] * sats]) |
| 1635 | |
| 1636 | |
| 1637 | def _all_points_on_plane(xs, ys, zs, atol=1e-8): |
no test coverage detected
searching dependent graphs…