8000 Unexpected tick spacing for datetime axes · Issue #19090 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
Unexpected tick spacing for datetime axes #19090
Closed
@tillahoffmann

Description

@tillahoffmann

Bug report

Bug summary

Tick labels on some datetime axes are not spaced regularly by default. Feel free to close if this behaviour is intended.

Code for reproduction

import numpy as np
from matplotlib import pyplot as plt

# Set up some datetime values
x = np.asarray(['2020-07-06', '2020-08-02', '2020-08-21', '2020-09-07',
                '2020-09-25', '2020-10-14', '2020-11-04', '2020-11-22'], 
               dtype=np.datetime64)
# Plot the dates
fig, ax = plt.subplots()
ax.scatter(x, np.arange(len(x)))
# Optional, make the labels a bit more readable
plt.setp(ax.xaxis.get_ticklabels(), rotation=30)
# Get the tick locations and calculate spacings
locs = ax.xaxis.get_ticklocs()
deltas = np.diff(locs)
deltas

Actual outcome

image

# result of `deltas` statement
array([21., 10., 21., 10., 21.,  9., 21., 10., 21.])

Expected outcome

The same plot but with regular spacing of ticks.

Matplotlib version

  • Operating system: macOS Big Sur 11.0.1
  • Matplotlib version: 3.2.2 (installed via pip in a virtual environment)
  • Matplotlib backend (print(matplotlib.get_backend())): module://ipykernel.pylab.backend_inline
  • Python version: 3.8.1 (default, Jun 21 2020, 11:47:47); [Clang 11.0.0 (clang-1100.0.33.17)]
  • Jupyter version (if applicable):
    • jupyter core : 4.6.3
    • jupyter-notebook : 6.0.3
    • qtconsole : 4.7.5
    • ipython : 7.16.1
    • ipykernel : 5.3.2
    • jupyter client : 6.1.5
    • jupyter lab : 2.2.9
    • nbconvert : 5.6.1
    • ipywidgets : 7.5.1
    • nbformat : 5.0.7
    • traitlets : 4.3.3
  • Other libraries: numpy==1.19.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0