Skip to content

Plot_date default date format is not always the same #9765

Closed
@mirkocoric

Description

@mirkocoric

Bug report

Bug summary

In the example below date format is changed when plotting with plot_date after calling dates.DayLocator(). This can be fixed with using dates.DateFormatter(), but the confusion could be avoided if plot_date uses the same date format when it is not specified by user.

Code for reproduction

import datetime
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

DATE1 = mdates.date2num(datetime.datetime(2017, 8, 10, 18, 0))
DATE2 = mdates.date2num(datetime.datetime(2017, 8, 11, 18, 0))
DATE3 = mdates.date2num(datetime.datetime(2017, 8, 12, 18, 0))
plt.plot_date([DATE1, DATE2, DATE3], [1, 2, 3], '-')
plt.show()

plt.plot_date([DATE1, DATE2, DATE3], [1, 2, 3], '-')
plt.gca().xaxis.set_major_locator(mdates.DayLocator())
plt.show()

Actual outcome

beforedaylocator

afterdaylocator

Matplotlib version

  • Operating system: Mac OS
  • Matplotlib version: 2.0.2
  • Matplotlib backend (print(matplotlib.get_backend())):
  • Python version: 2.7.13
  • Jupyter version (if applicable):
  • Other libraries:

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