Skip to content

BUG/VIS: can't add a line with DatetimeIndex/datetime64 as x-values on timeseries plot #9053

Open
@jorisvandenbossche

Description

@jorisvandenbossche

If you do a time series plot:

s = pd.Series(np.random.randn(100), index=pd.date_range('1970-01-02', periods=100, freq='T'))
fig, ax = plt.subplots()
s.plot(ax=ax)

and then want to add a line through matplotlib using the index or datetime64 values, this does not work (it plots the data at a totally wrong place outside of sight in this case):

ax.plot(s.index, s.values, color='g')
# or
ax.plot(s.index.values, s.values, color='r')

This is because PeriodConverter cannot deal with datetime64 values (Period/PeriodIndex also cannot deal with them), while when plotting this through the pandas plot interface, the datetime64 values will first be converted to periods.

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