Skip to content

Weird DatetimeIndex + secondary y axis plotting issue #18768

@soxofaan

Description

@soxofaan

Today I stumbled on weird issue with plotting two series with a datetimeindex and a secondary axis.

Code that illustrates the problem:

a = pd.Series(
    [16, 13, 11],
    index=pd.to_datetime(['2017-09-13', '2017-09-14', '2017-09-16'], format='%Y-%m-%d')
)
b = pd.Series(
    [23, 27, 25],
    index=pd.to_datetime(['2017-09-13', '2017-09-14', '2017-09-15'], format='%Y-%m-%d')
)

# Combinations of `secondary_y` values to try out.
secondary_ys = [(False, False), (False, True), (True, False), (True, True)]

fig, axes = plt.subplots(figsize=(10, 2), ncols=4, nrows=1)
for (sya, syb), ax in zip(secondary_ys, axes.flat):
    a.plot(ax=ax, style='o-', secondary_y=sya)
    b.plot(ax=ax, style='x-', secondary_y=syb)
    ax.set_title('a:%r - b:%r' % (sya, syb))
  • b is a straightforward time series with successive days
  • a has a one day jump in the last item
  • the for loop tries out all the possible combinations of assigning these two series to the primary or secondary y axis in a plot
  • Whenever one or more series is assigned to the secondary y axis, the x axis is completely confused:

screen shot 2017-12-13 at 18 21 48

More in depth experimentation (and version information) can be found in the notebook at https://gist.github.com/soxofaan/9fdfdeafb8fb555dd8547bc48a27e2f3
(also notice the inconsistant x axes label formatting and orientation)

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