8000 Clarify tick collision API change doc. by anntzer · Pull Request #13632 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Clarify tick collision API change doc. #13632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 8, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions doc/api/next_api_changes/2018-01-30-AL.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,40 @@
Minor Locator no longer try to avoid overstriking major Locators
````````````````````````````````````````````````````````````````
Minor ticks that collide with major ticks are always hidden
```````````````````````````````````````````````````````````

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

This logic has now moved to the Axis class; thus, for example,
``xaxis.minor.locator()`` now includes positions that collide with
``xaxis.major.locator()``, but ``xaxis.get_minorticklocs()`` does not.
This logic has now moved to the Axis class, and is used *regardless of the
ticker class*. ``xaxis.minor.locator()`` now includes positions that collide
with ``xaxis.major.locator()``, but ``xaxis.get_minorticklocs()`` does not.

If you were relying on both the major and minor tick labels to appear on the
same tick, you may need to update your code. For example, the following
snippet labeled days using major ticks, and hours and minutes using minor
ticks::

import numpy as np
import matplotlib.dates as mdates
import matplotlib.pyplot as plt

t = np.arange("2018-11-03", "2018-11-06", dtype="datetime64")
x = np.random.rand(len(t))

fig, ax = plt.subplots()
ax.plot(t, x)
ax.xaxis.set(
major_locator=mdates.DayLocator(),
major_formatter=mdates.DateFormatter("\n%a"),
minor_locator=mdates.HourLocator((0, 6, 12, 18)),
minor_formatter=mdates.DateFormatter("%H:%M"),
)

plt.show()

and added a newline to the major ticks labels to avoid them crashing into the
minor tick labels.

With the API change, the major tick labels should also include hours and
minutes, as the minor ticks are gone, so the ``major_formatter`` should be
``mdates.DateFormatter("%H:%M\n%a")``.
0