| 2478 | np.log(x) / np.log(self._base)) |
| 2479 | |
| 2480 | def tick_values(self, vmin, vmax): |
| 2481 | n_request = ( |
| 2482 | self.numticks if self.numticks != "auto" else |
| 2483 | np.clip(self.axis.get_tick_space(), 2, 9) if self.axis is not None else |
| 2484 | 9) |
| 2485 | |
| 2486 | b = self._base |
| 2487 | if vmin <= 0.0: |
| 2488 | if self.axis is not None: |
| 2489 | vmin = self.axis.get_minpos() |
| 2490 | |
| 2491 | if vmin <= 0.0 or not np.isfinite(vmin): |
| 2492 | raise ValueError( |
| 2493 | "Data cannot be log-scaled because all values are <= 0.") |
| 2494 | |
| 2495 | if vmax < vmin: |
| 2496 | vmin, vmax = vmax, vmin |
| 2497 | # Min and max exponents, float and int versions; e.g., if vmin=10^0.3, |
| 2498 | # vmax=10^6.9, then efmin=0.3, emin=1, emax=6, efmax=6.9, n_avail=6. |
| 2499 | efmin, efmax = self._log_b([vmin, vmax]) |
| 2500 | emin = math.ceil(efmin) |
| 2501 | emax = math.floor(efmax) |
| 2502 | n_avail = emax - emin + 1 # Total number of decade ticks available. |
| 2503 | |
| 2504 | if isinstance(self._subs, str): |
| 2505 | if n_avail >= 10 or b < 3: |
| 2506 | if self._subs == 'auto': |
| 2507 | return np.array([]) # no minor or major ticks |
| 2508 | else: |
| 2509 | subs = np.array([1.0]) # major ticks |
| 2510 | else: |
| 2511 | _first = 2.0 if self._subs == 'auto' else 1.0 |
| 2512 | subs = np.arange(_first, b) |
| 2513 | else: |
| 2514 | subs = self._subs |
| 2515 | |
| 2516 | # Get decades between major ticks. Include an extra tick outside the |
| 2517 | # lower and the upper limit: QuadContourSet._autolev relies on this. |
| 2518 | if mpl.rcParams["_internal.classic_mode"]: # keep historic formulas |
| 2519 | stride = max(math.ceil((n_avail - 1) / (n_request - 1)), 1) |
| 2520 | decades = np.arange(emin - stride, emax + stride + 1, stride) |
| 2521 | else: |
| 2522 | # *Determine the actual number of ticks*: Find the largest number |
| 2523 | # of ticks, no more than the requested number, that can actually |
| 2524 | # be drawn (e.g., with 9 decades ticks, no stride yields 7 |
| 2525 | # ticks). For a given value of the stride *s*, there are either |
| 2526 | # floor(n_avail/s) or ceil(n_avail/s) ticks depending on the |
| 2527 | # offset. Pick the smallest stride such that floor(n_avail/s) < |
| 2528 | # n_request, i.e. n_avail/s < n_request+1, then re-set n_request |
| 2529 | # to ceil(...) if acceptable, else to floor(...) (which must then |
| 2530 | # equal the original n_request, i.e. n_request is kept unchanged). |
| 2531 | stride = n_avail // (n_request + 1) + 1 |
| 2532 | nr = math.ceil(n_avail / stride) |
| 2533 | if nr <= n_request: |
| 2534 | n_request = nr |
| 2535 | else: |
| 2536 | assert nr == n_request + 1 |
| 2537 | if n_request == 0: # No tick in bounds; two ticks just outside. |