Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

added test_axhspan in test_datetime.py #27139

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 20, 2023
Merged
Changes from all 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
37 changes: 34 additions & 3 deletions 37 lib/matplotlib/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,42 @@ def test_axhline(self):
fig, ax = plt.subplots()
ax.axhline(...)

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

start_date = datetime.datetime(2023, 1, 1)
dates = [start_date + datetime.timedelta(days=i) for i in range(31)]
numbers = list(range(1, 32))

fig, (ax1, ax2, ax3) = plt.subplots(3, 1,
constrained_layout=True,
figsize=(10, 12))

ax1.plot(dates, numbers, marker='o', color='blue')
for i in range(0, 31, 2):
ax1.axhspan(ymin=i+1, ymax=i+2, facecolor='green', alpha=0.5)
ax1.set_title('Datetime vs. Number')
ax1.set_xlabel('Date')
ax1.set_ylabel('Number')

ax2.plot(numbers, dates, marker='o', color='blue')
for i in range(0, 31, 2):
ymin = start_date + datetime.timedelta(days=i)
ymax = ymin + datetime.timedelta(days=1)
ax2.axhspan(ymin=ymin, ymax=ymax, facecolor='green', alpha=0.5)
ax2.set_title('Number vs. Datetime')
ax2.set_xlabel('Number')
ax2.set_ylabel('Date')

ax3.plot(dates, dates, marker='o', color='blue')
for i in range(0, 31, 2):
ymin = start_date + datetime.timedelta(days=i)
ymax = ymin + datetime.timedelta(days=1)
ax3.axhspan(ymin=ymin, ymax=ymax, facecolor='green', alpha=0.5)
ax3.set_title('Datetime vs. Datetime')
ax3.set_xlabel('Date')
ax3.set_ylabel('Date')

@pytest.mark.xfail(reason="Test for axline not written yet")
@mpl.style.context("default")
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.