-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[TST] Added test_arrow in test_datetime.py #27372
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mostly some things to think about, I would like to know about the d[xy]
values in particular.
linewidth=3, | ||
facecolor='red', | ||
edgecolor='red', | ||
transform=ax1.transData) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
specifying the transform as transData
is not necessary, as that is the default.
ax1.plot(dates, y_values, marker='o') | ||
ax1.arrow(x=dates[10], | ||
y=10, | ||
dx=10, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect the d[xy]
values that are used on date-based axes to be timedelta
rather than raw numbers (and in particular if it doesn't work that is something we should look at)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your review. Unfortunately, currently the function ax.arrow
expects the dx
, dy
to be in the axis units only. We have discovered another issue while implementing datetime test.
Looks like this PR would be blocked meanwhile.
I have tested a minimal change here to get the timedelta working when dx=datetime.timedelta(days=10)
with the following patch.
New unitless d[xy]
are computed before passing down to the function mpatches.FancyArrow
. The drawback is that we now need to import datetime object dependence into the lib/matplotlib/axes/_axes.py
. Would be appreciated if you would suggest a better approach to implement the d[xy] timedelta support.
diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py
index 2136ecb2eb..780e5048e0 100644
--- a/lib/matplotlib/axes/_axes.py
+++ b/lib/matplotlib/axes/_axes.py
@@ -3,6 +3,7 @@ import itertools
import logging
import math
from numbers import Integral, Number, Real
+import datetime
import numpy as np
from numpy import ma
@@ -5218,13 +5219,22 @@ default: :rc:`scatter.edgecolors`
... arrowprops=dict(arrowstyle="->"))
"""
+ old_x=x
+ old_y=y
# Strip away units for the underlying patch since units
# do not make sense to most patch-like code
x = self.convert_xunits(x)
y = self.convert_yunits(y)
- dx = self.convert_xunits(dx)
- dy = self.convert_yunits(dy)
-
+ # if dx is timedelta, compute the unitless dx after convert
+ if isinstance(dx, datetime.timedelta):
+ dx = self.convert_xunits( old_x + dx ) - x
+ else:
+ dx = self.convert_xunits(dx)
+ # if dy is timedelta, compute the unitless dy after convert
+ if isinstance(dy, datetime.timedelta):
+ dy = self.convert_xunits( old_y + dy ) - y
+ else:
+ dy = self.convert_yunits(dy)
a = mpatches.FancyArrow(x, y, dx, dy, **kwargs)
self.add_patch(a)
self._request_autoscale_view()
OverviewHey @samchan2022 and @dstansby, I have joined the Understanding The IssueAfter spending some time trying to reading through the documentation provided, I believe that this issue is asking us to modify the following part of
We can do this by filling in the [Basic] Proposed SolutionWe can start by removing the
We may also want to test Next Steps / QuestionsI would appreciate it if I was assigned this issue and I would love more guidance. I'll be sure to send messages in the
Please feel free to ask me any questions or provide more explanation if necessary. I look forward to becoming a contributor to matplotlib!😁 |
PR summary
This PR adds a smoke test for Axes.arrow in lib/matplotlib/tests/test_datetime.py. This PR closes one of the items listed in the issue #26864.

Smoke test Plot:
PR checklist