Skip to content

Unevenly spaced ticks in plot_date() #13183

Closed
@chrisjbillington

Description

@chrisjbillington

Bug report

When plotting with plot_date(), the x axis ticks can be unevenly spaced. It looks like when the tick spacing is less than a month, the start of the month is always present as a tick, which may mean the space between it and the previous tick is small. This can lead to overlapping tick labels and generally poor looking axes and grids.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

start = np.datetime64('2018-01-01', 'D')
end = np.datetime64('2018-04-01', 'D')
dates = np.arange(start, end)
data = np.random.randn(len(dates))

plt.plot_date(dates, data)
plt.grid(True)
plt.gcf().autofmt_xdate()
plt.show()

Actual outcome

image

Expected outcome

The plot should have evenly spaced gridlines and axis ticks, unless a custom locator has specified otherwise.

Matplotlib version

  • Operating system: Arch Linux
  • Matplotlib version: 3.0.2
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.7.2
  • Jupyter version (if applicable): n/a
  • Other libraries: matplotlib 1.15.4

Matplotlib, Python and numpy are installed with the OS package manager using the standard Arch Linux repositories.

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