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

Skip to content

Add test_quiver in test_datetime.py #27407

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
15 changes: 12 additions & 3 deletions lib/matplotlib/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,11 +446,20 @@ def test_plot_date(self):
ax2.plot_date(x_dates, y_ranges)
ax3.plot_date(x_ranges, y_dates)

@pytest.mark.xfail(reason="Test for quiver not written yet")
@mpl.style.context("default")
def test_quiver(self):
fig, ax = plt.subplots()
ax.quiver(...)
dates = [datetime.datetime(2023, 1, 1) + datetime.timedelta(days=i)
for i in range(5)]
x = dates
y = np.zeros_like(x, dtype=float)
u = np.sin(np.arange(len(x)))
v = np.cos(np.arange(len(x)))
fig, ax = plt.subplots(figsize=(10, 6))
ax.quiver(x, y, u, v, scale=20)
Copy link
Member

Choose a reason for hiding this comment

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

It seems like y could also be tested? I'm not sure if it also makes sense to try u and v as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Quiver plots typically expect numerical values for u and v (representing vector components), and y is usually a numerical position value. Using datetime objects for these variables would be unconventional and might not work directly with the quiver plot functionality. I think it might be better to maintain the test as is.

Copy link
Member

Choose a reason for hiding this comment

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

I don't really follow the assertion that y is usually a numerical position value. But in any case, these tests are to check whether the code works, not what the "usual" type is. We absolutely want to test things that are unusual.

Copy link
Member

Choose a reason for hiding this comment

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

I agree that y is not actually different from x here and should be tested, additionally I do think u/v should be tested with angles="xy" and u/v supplied as timedeltas. I think passing u/v as timedeltas should not be included with the (default) angles="uv"

fig.autofmt_xdate()
ax.set_title('Quiver Plot with Datetime Data')
ax.set_xlabel('Date')
ax.set_ylabel('Y-axis')

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