(self)
| 875 | self._orderOfMagnitude = 0 |
| 876 | |
| 877 | def _set_format(self): |
| 878 | # set the format string to format all the ticklabels |
| 879 | if len(self._locs) < 2: |
| 880 | # Temporarily augment the locations with the axis end points. |
| 881 | _locs = [*self._locs, *self.axis.get_view_interval()] |
| 882 | else: |
| 883 | _locs = self._locs |
| 884 | locs = (np.asarray(_locs) - self.offset) / 10. ** self._orderOfMagnitude |
| 885 | loc_range = np.ptp(locs) |
| 886 | # Curvilinear coordinates can yield two identical points. |
| 887 | if loc_range == 0: |
| 888 | loc_range = np.max(np.abs(locs)) |
| 889 | # Both points might be zero. |
| 890 | if loc_range == 0: |
| 891 | loc_range = 1 |
| 892 | if len(self._locs) < 2: |
| 893 | # We needed the end points only for the loc_range calculation. |
| 894 | locs = locs[:-2] |
| 895 | loc_range_oom = int(math.floor(math.log10(loc_range))) |
| 896 | # first estimate: |
| 897 | sigfigs = max(0, 3 - loc_range_oom) |
| 898 | # refined estimate: |
| 899 | thresh = 1e-3 * 10 ** loc_range_oom |
| 900 | while sigfigs >= 0: |
| 901 | if np.abs(locs - np.round(locs, decimals=sigfigs)).max() < thresh: |
| 902 | sigfigs -= 1 |
| 903 | else: |
| 904 | break |
| 905 | sigfigs += 1 |
| 906 | self._format = f'%1.{sigfigs}f' |
| 907 | if self._usetex or self._useMathText: |
| 908 | self._format = r'$\mathdefault{%s}$' % self._format |
| 909 | |
| 910 | |
| 911 | class LogFormatter(Formatter): |
no test coverage detected