(darray, vmin, vmax, robust)
| 751 | |
| 752 | |
| 753 | def _rescale_imshow_rgb(darray, vmin, vmax, robust): |
| 754 | assert robust or vmin is not None or vmax is not None |
| 755 | |
| 756 | # Calculate vmin and vmax automatically for `robust=True` |
| 757 | if robust: |
| 758 | if vmax is None: |
| 759 | vmax = np.nanpercentile(darray, 100 - ROBUST_PERCENTILE) |
| 760 | if vmin is None: |
| 761 | vmin = np.nanpercentile(darray, ROBUST_PERCENTILE) |
| 762 | # If not robust and one bound is None, calculate the default other bound |
| 763 | # and check that an interval between them exists. |
| 764 | elif vmax is None: |
| 765 | vmax = 255 if np.issubdtype(darray.dtype, np.integer) else 1 |
| 766 | if vmax < vmin: |
| 767 | raise ValueError( |
| 768 | f"vmin={vmin!r} is less than the default vmax ({vmax!r}) - you must supply " |
| 769 | "a vmax > vmin in this case." |
| 770 | ) |
| 771 | elif vmin is None: |
| 772 | vmin = 0 |
| 773 | if vmin > vmax: |
| 774 | raise ValueError( |
| 775 | f"vmax={vmax!r} is less than the default vmin (0) - you must supply " |
| 776 | "a vmin < vmax in this case." |
| 777 | ) |
| 778 | # Scale interval [vmin .. vmax] to [0 .. 1], with darray as 64-bit float |
| 779 | # to avoid precision loss, integer over/underflow, etc with extreme inputs. |
| 780 | # After scaling, downcast to 32-bit float. This substantially reduces |
| 781 | # memory usage after we hand `darray` off to matplotlib. |
| 782 | darray = ((darray.astype("f8") - vmin) / (vmax - vmin)).astype("f4") |
| 783 | return np.minimum(np.maximum(darray, 0), 1) |
| 784 | |
| 785 | |
| 786 | def _update_axes( |
no test coverage detected
searching dependent graphs…