-
-
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
Open
samchan2022
wants to merge
1
commit into
matplotlib:main
Choose a base branch
from
samchan2022:arrow-test-datetime
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,11 +20,61 @@ def test_annotate(self): | |
fig, ax = plt.subplots() | ||
ax.annotate(...) | ||
|
||
@pytest.mark.xfail(reason="Test for arrow not written yet") | ||
@mpl.style.context("default") | ||
def test_arrow(self): | ||
fig, ax = plt.subplots() | ||
ax.arrow(...) | ||
mpl.rcParams["date.converter"] = 'concise' | ||
fig, (ax1, ax2, ax3) = plt.subplots(3, 1, | ||
constrained_layout=True, | ||
figsize=(10, 12)) | ||
|
||
start_date = datetime.datetime(2023, 1, 1) | ||
dates = [start_date + datetime.timedelta(days=i) for i in range(31)] | ||
y_values = range(31) | ||
|
||
ax1.plot(dates, y_values, marker='o') | ||
ax1.arrow(x=dates[10], | ||
y=10, | ||
dx=10, | ||
dy=10, | ||
head_width=1, | ||
head_length=1, | ||
linewidth=3, | ||
facecolor='red', | ||
edgecolor='red', | ||
transform=ax1.transData) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. specifying the transform as |
||
ax1.set_title('Datetime vs. Number') | ||
ax1.set_xlabel('Date') | ||
ax1.set_ylabel('Number') | ||
|
||
ax2.plot(y_values, dates, marker='o') | ||
ax2.arrow(x=10, | ||
y=dates[10], | ||
dx=10, | ||
dy=10, | ||
head_width=1, | ||
head_length=1, | ||
linewidth=3, | ||
facecolor='red', | ||
edgecolor='red', | ||
transform=ax2.transData) | ||
ax2.set_title('Number vs. Datetime') | ||
ax2.set_xlabel('Number') | ||
ax2.set_ylabel('Date') | ||
|
||
ax3.plot(dates, dates, marker='o') | ||
ax3.arrow(x=dates[10], | ||
y=dates[10], | ||
dx=10, | ||
dy=10, | ||
head_width=1, | ||
head_length=1, | ||
linewidth=3, | ||
facecolor='red', | ||
edgecolor='red', | ||
transform=ax3.transData) | ||
ax3.set_title('Datetime vs. Datetime') | ||
ax3.set_xlabel('Date') | ||
ax3.set_ylabel('Date') | ||
|
||
@mpl.style.context("default") | ||
def test_axhline(self): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 betimedelta
rather than raw numbers (and in particular if it doesn't work that is something we should look at)Uh oh!
There was an error while loading. Please reload this page.
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 thedx
,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 functionmpatches.FancyArrow
. The drawback is that we now need to import datetime object dependence into thelib/matplotlib/axes/_axes.py
. Would be appreciated if you would suggest a better approach to implement the d[xy] timedelta support.