Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Add test_barh to test_datetime.py#27084

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
QuLogic merged 4 commits intomatplotlib:mainfromCozyFrog:tst/dt-unit-test
Oct 18, 2023

Conversation

CozyFrog
Copy link
Contributor

PR summary

I have added a datetime/timedelta smoke test forAxes.barh inlib/matplotlib/tests/test_datetime.py.
This addresses theAxes.barh task from#26864.

The image below is the plot generated from this smoke test/example code.
barh_smoke_test

PR checklist

Copy link

@github-actionsgithub-actionsbot left a comment

Choose a reason for hiding this comment

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

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.

You can also join uson gitter for real-time discussion.

For details on testing, writing docs, and our review process, please seethe developer guide

We strive to be a welcoming and open project. Please follow ourCode of Conduct.

Copy link
Member

@ksundenksunden left a comment

Choose a reason for hiding this comment

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

See comment from#27033 (review):

(Copied here for convenience, note that it was written originally forbar, so swap horizontal/vertical etc, but the sentiment is the same)

I think the bar graphs with dates on the vertical (forbar, horizonatal forbarh) axis should be given a bit more care here. That there is an implicit0 mark, which results in1970-01-01 is not a particularly good representation of a bar plot.

I think that for this, there should be abottom argument specified as a datetime and then using atimedelta instead of adatetime for the heights, as indicated by thebardocstring

Here is some code I wrote for someone who had started working on this but never opened a PR:

importmatplotlib.pyplotaspltimportnumpyasnpfromdatetimeimportdatetime,timedeltaimportmatplotlibasmplmpl.rcParams["date.converter"]='concise'fig, (ax1,ax2)=plt.subplots(2,1,layout='constrained')price_date=np.array([datetime(2020,6,30),datetime(2020,7,22),datetime(2020,8,3),datetime(2020,9,14)],dtype=np.datetime64)price_close= [8800,2600,8500,7400]start_date=np.datetime64(datetime(2020,6,1))ax1.bar(price_date,price_close,width=np.timedelta64(4,"D"))ax2.bar(np.arange(4),price_date-start_date,bottom=start_date)

Note thestart_date andprice_date-start_date in this example.

CozyFrog reacted with thumbs up emoji
@ksunden
Copy link
Member

I would also rather explictlyavoid having the times be in 1970 to make sure we arent falling into certain traps with datetimes.

CozyFrog reacted with thumbs up emoji

@QuLogicQuLogic mentioned this pull requestOct 13, 2023
64 tasks
@CozyFrog
Copy link
ContributorAuthor

Thank you so much for your notes and sample code, I appreciate the help!

@CozyFrog
Copy link
ContributorAuthor

I have made a few fixes.

  • The test now consists of two subplots; one passes datetime and timedelta arguments to they andheight parameters respectively, and the other passes timedelta and datetime arguments to thewidth andleft parameters respectively.
  • The times are in 2020 now to avoid any datetime traps.

Below is an image of the new test:
barh_smoke_test_second_pr

@QuLogicQuLogic merged commit9db1bca intomatplotlib:mainOct 18, 2023
@QuLogic
Copy link
Member

Thanks@CozyFrog! Congratulations on your first PR to Matplotlib 🎉 We hope to hear from you again.

CozyFrog reacted with laugh emoji

@CozyFrogCozyFrog deleted the tst/dt-unit-test branchOctober 18, 2023 19:27
@QuLogicQuLogic added this to thev3.9.0 milestoneOct 25, 2023
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@github-actionsgithub-actions[bot]github-actions[bot] left review comments

@QuLogicQuLogicQuLogic approved these changes

@ksundenksundenksunden approved these changes

Assignees
No one assigned
Projects
Milestone
v3.9.0
Development

Successfully merging this pull request may close these issues.

4 participants
@CozyFrog@ksunden@QuLogic@melissawm

[8]ページ先頭

©2009-2025 Movatter.jp