|
1 |
| -Minor Locator no longer try to avoid overstriking major Locators |
2 |
| -```````````````````````````````````````````````````````````````` |
| 1 | +Minor ticks that collide with major ticks are always hidden |
| 2 | +``````````````````````````````````````````````````````````` |
3 | 3 |
|
4 | 4 | Previously, certain locator classes (`LogLocator`, `AutoMinorLocator`)
|
5 | 5 | contained custom logic to avoid emitting tick locations that collided with
|
6 | 6 | major ticks when they were used as minor locators.
|
7 | 7 |
|
8 |
| -This logic has now moved to the Axis class; thus, for example, |
9 |
| -``xaxis.minor.locator()`` now includes positions that collide with |
10 |
| -``xaxis.major.locator()``, but ``xaxis.get_minorticklocs()`` does not. |
| 8 | +This logic has now moved to the Axis class, and is used *regardless of the |
| 9 | +ticker class*. ``xaxis.minor.locator()`` now includes positions that collide |
| 10 | +with ``xaxis.major.locator()``, but ``xaxis.get_minorticklocs()`` does not. |
| 11 | + |
| 12 | +If you were relying on both the major and minor tick labels to appear on the |
| 13 | +same tick, you may need to update your code. For example, the following |
| 14 | +snippet labeled days using major ticks, and hours and minutes using minor |
| 15 | +ticks:: |
| 16 | + |
| 17 | + import numpy as np |
| 18 | + import matplotlib.dates as mdates |
| 19 | + import matplotlib.pyplot as plt |
| 20 | + |
| 21 | + t = np.arange("2018-11-03", "2018-11-06", dtype="datetime64") |
| 22 | + x = np.random.rand(len(t)) |
| 23 | + |
| 24 | + fig, ax = plt.subplots() |
| 25 | + ax.plot(t, x) |
| 26 | + ax.xaxis.set( |
| 27 | + major_locator=mdates.DayLocator(), |
| 28 | + major_formatter=mdates.DateFormatter("\n%a"), |
| 29 | + minor_locator=mdates.HourLocator((0, 6, 12, 18)), |
| 30 | + minor_formatter=mdates.DateFormatter("%H:%M"), |
| 31 | + ) |
| 32 | + |
| 33 | + plt.show() |
| 34 | + |
| 35 | +and added a newline to the major ticks labels to avoid them crashing into the |
| 36 | +minor tick labels. |
| 37 | + |
| 38 | +With the API change, the major tick labels should also include hours and |
| 39 | +minutes, as the minor ticks are gone, so the ``major_formatter`` should be |
| 40 | +``mdates.DateFormatter("%H:%M\n%a")``. |
0 commit comments