Skip to content

Commit bcfcea9

Browse files
authored
Merge pull request #13635 from meeseeksmachine/auto-backport-of-pr-13632-on-v3.1.x
Backport PR #13632 on branch v3.1.x (Clarify tick collision API change doc.)
2 parents 098b00e + 336dd46 commit bcfcea9

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed
Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,40 @@
1-
Minor Locator no longer try to avoid overstriking major Locators
2-
````````````````````````````````````````````````````````````````
1+
Minor ticks that collide with major ticks are always hidden
2+
```````````````````````````````````````````````````````````
33

44
Previously, certain locator classes (`LogLocator`, `AutoMinorLocator`)
55
contained custom logic to avoid emitting tick locations that collided with
66
major ticks when they were used as minor locators.
77

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

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy