Closed as not planned
Description
Bug summary
The ordering of fill_between
and pandas.DataFrame/Series.plot with datetime index differs
Code for reproduction
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
n_dates = 52 * 3
dates = pd.date_range("2022-01-01", periods=n_dates, freq="W-MON")
seed = sum(map(ord, "Order matters"))
rng = np.random.default_rng(seed)
data = rng.normal(size=n_dates).cumsum()
ser = pd.Series(data, index=dates)
padding = 15
fig, axes = plt.subplots(nrows=2, ncols=2, sharex=False, sharey=True)
def plot_time_series(pandas: bool, ax: plt.Axes):
if pandas:
ser.plot(ax=ax)
else:
ax.plot(dates, data)
def plot_fill_between(ax: plt.Axes):
ax.fill_between(dates, data - padding, data + padding, alpha=0.25)
ax = axes[0, 0]
plot_time_series(pandas=True, ax=ax)
plot_fill_between(ax)
ax.set(title="time-series first", ylabel="pandas.Series.plot")
ax = axes[0, 1]
plot_fill_between(ax)
plot_time_series(pandas=True, ax=ax)
ax.set(title="time-series second")
ax = axes[1, 0]
plot_time_series(pandas=False, ax=ax)
plot_fill_between(ax)
ax.set(title="", ylabel="plt.plot")
ax = axes[1, 1]
plot_fill_between(ax)
plot_time_series(pandas=False, ax=ax)
ax.set(title="")
plt.show()
Actual outcome
Expected outcome
Both orders would work the same
Additional information
No response
Operating system
No response
Matplotlib Version
3.8.3
EDIT: 3.9.0 as well
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
None
Metadata
Metadata
Assignees
Labels
No labels