Center the pixels on the coordinates.
(x)
| 1826 | ) |
| 1827 | |
| 1828 | def _center_pixels(x): |
| 1829 | """Center the pixels on the coordinates.""" |
| 1830 | if np.issubdtype(x.dtype, str): |
| 1831 | # When using strings as inputs imshow converts it to |
| 1832 | # integers. Choose extent values which puts the indices in |
| 1833 | # in the center of the pixels: |
| 1834 | return 0 - 0.5, len(x) - 0.5 |
| 1835 | |
| 1836 | try: |
| 1837 | # Center the pixels assuming uniform spacing: |
| 1838 | xstep = 0.5 * (x[1] - x[0]) |
| 1839 | except IndexError: |
| 1840 | # Arbitrary default value, similar to matplotlib behaviour: |
| 1841 | xstep = 0.1 |
| 1842 | |
| 1843 | return x[0] - xstep, x[-1] + xstep |
| 1844 | |
| 1845 | # Center the pixels: |
| 1846 | left, right = _center_pixels(x) |
no outgoing calls
no test coverage detected
searching dependent graphs…