Return a readable tick spacing close to span / target_ticks.
(span, target_ticks)
| 36 | |
| 37 | |
| 38 | def nice_step(span, target_ticks): |
| 39 | """Return a readable tick spacing close to span / target_ticks.""" |
| 40 | if span <= 0: |
| 41 | return 1.0 |
| 42 | |
| 43 | raw = span / target_ticks |
| 44 | magnitude = 10 ** math.floor(math.log10(raw)) |
| 45 | normalized = raw / magnitude |
| 46 | for step in (1, 2, 2.5, 5, 10): |
| 47 | if normalized <= step: |
| 48 | return step * magnitude |
| 49 | return 10 * magnitude |
| 50 | |
| 51 | |
| 52 | def fmt_tick(value): |