Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bcfcea9

Browse filesBrowse 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
Copy full SHA for bcfcea9

File tree

Expand file treeCollapse file tree

1 file changed

+35
-5
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+35
-5
lines changed
+35-5Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.