Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add test_vlines to test_datetime.py #27410

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 1 commit into from
Dec 6, 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
22 changes: 19 additions & 3 deletions lib/matplotlib/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,24 @@ def test_violinplot(self):
fig, ax = plt.subplots()
ax.violinplot(...)

@pytest.mark.xfail(reason="Test for vlines not written yet")
@mpl.style.context("default")
def test_vlines(self):
fig, ax = plt.subplots()
ax.vlines(...)
mpl.rcParams["date.converter"] = 'concise'
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, layout='constrained')
ax1.set_xlim(left=datetime.datetime(2023, 1, 1),
right=datetime.datetime(2023, 6, 30))
ax1.vlines(x=[datetime.datetime(2023, 2, 10),
datetime.datetime(2023, 5, 18),
datetime.datetime(2023, 6, 6)],
ymin=[0, 0.25, 0.5],
ymax=[0.25, 0.5, 0.75])
ax2.set_xlim(left=0,
right=0.5)
ax2.vlines(x=[0.3, 0.35],
ymin=[np.datetime64('2023-03-20'), np.datetime64('2023-03-31')],
ymax=[np.datetime64('2023-05-01'), np.datetime64('2023-05-16')])
ax3.set_xlim(left=datetime.datetime(2023, 7, 1),
right=datetime.datetime(2023, 12, 31))
ax3.vlines(x=[datetime.datetime(2023, 9, 1), datetime.datetime(2023, 12, 10)],
Copy link
Member

Choose a reason for hiding this comment

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

Any reason not to re-use dates on this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to make each graph look fairly different from one other, so I tried to pick different dates and x/y limits. Initially, the dates array was too long to fit on one line which is why I made it a separate variable. If you'd prefer I re-use it, I can make the change but would have to modify the x limit as well because the values in dates fall outside of the current range for ax3. Let me know what you think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alternatively, I could get rid of dates altogether and move the array directly into ax1.vlines() but keep each element on a different line like it is right now

Copy link
Member

Choose a reason for hiding this comment

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

Yea, I think it'd be clearer to not have dates if it's not being reused in other places with dates.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it. Just fixed it

ymin=datetime.datetime(2023, 1, 15),
ymax=datetime.datetime(2023, 1, 30))