8000 added test_axvspan in test.datetime.py by danielcobej · Pull Request #27130 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

added test_axvspan in test.datetime.py #27130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions lib/matplotlib/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,35 @@ def test_axvline(self):
fig, ax = plt.subplots()
ax.axvline(...)

@pytest.mark.xfail(reason="Test for axvspan not written yet")
@mpl.style.context("default")
def test_axvspan(self):
fig, ax = plt.subplots()
ax.axvspan(...)
mpl.rcParams["date.converter"] = 'concise'
np.random.seed(19680801)

start_date = datetime.datetime(2023, 1, 1)
time_delta = datetime.timedelta(days=1)

values1 = np.random.randint(1, 10, 30)
values2 = np.random.randint(1, 10, 30)
values3 = np.random.randint(1, 10, 30)

bin_edges = [start_date + i * time_delta for i in range(31)]

fig, (ax1, ax2, ax3) = plt.subplots(3, 1, constrained_layout=True)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can shorten to fig, axes = plt.subplots(3, 1, constrained_layout=True), and remove axes = [ax1, ax2, ax3] below


axes = [ax1, ax2, ax3]
values_list = [values1, values2, values3]

for ax, values in zip(axes, values_list):
ax.hist(
[start_date + i * time_delta for i in range(30)],
bins=bin_edges,
weights=values
)
for i in range(np.random.randint(1, 5)):
xmin = start_date + np.random.randint(0, 30) * time_delta
xmax = xmin + np.random.randint(1, 3) * time_delta
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to my comment on #27139, please use hardcoded values here rather than random draws.

ax.axvspan(xmin=xmin, xmax=xmax, facecolor='green', alpha=0.5)

@pytest.mark.xfail(reason="Test for bar not written yet")
@mpl.style.context("default")
Expand Down
0