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

Modify rainbow_text() function to use annotate() function#25993

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

Conversation

niranjank2022
Copy link
Contributor

@niranjank2022niranjank2022 commentedMay 28, 2023
edited by rcomer
Loading

PR summary

This pull request is to modify the rainbow_text() function to use annotate() method.Closes#25941

PR checklist

@niranjank2022
Copy link
ContributorAuthor

Please tell whether my code is correct or anything can be changed. After that, I will work on documentation.

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 while, please feel free to ping@matplotlib/developers or anyone who has commented on the PR. 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.


def rainbow_text(x, y, strings, colors, orientation='horizontal',
ax=None, **kwargs):
"""
Take a list of *strings* and *colors* and place them next to each
Copy link
Member

Choose a reason for hiding this comment

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

Please leave the docstring in place.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

Sure.

t = text.get_transform() + \
offset_copy(Affine2D(), fig=fig, x=0, y=ex.height)
txt = ax.text(x, y, strings[0], color=colors[0], **kwargs)
for s, c in zip(strings[1:], colors[1:]):
Copy link
Member

Choose a reason for hiding this comment

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

you can directly dotxt = annotate() even if you use the previous value of txt as parameter.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

I think I have done it now.

@anntzer
Copy link
Contributor

The idea is correct. As noted by@timhoffm the code/docs simply needs to be cleaned up now.

@anntzeranntzer mentioned this pull requestMay 29, 2023
timhoffm
timhoffm previously requested changesMay 31, 2023
Copy link
Member

@timhoffmtimhoffm left a comment
edited
Loading

Choose a reason for hiding this comment

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

This introduces larger (unnatural) spacing.

new:
grafik

old:
grafik

@anntzer maybe you can comment on this as the use ofannotate() is your proposal.

@anntzer
Copy link
Contributor

Looks like just adding the space explicitly to each word (as was done previously) and not adding any offset works:

iforientation=='horizontal':txt=ax.text(x,y,strings[0]+" ",color=colors[0],**kwargs)fors,cinzip(strings[1:],colors[1:]):txt=ax.annotate(s+" ",xy=(1,0),xycoords=txt,va="bottom",color=c,**kwargs)eliforientation=='vertical':kwargs.update(rotation=90,verticalalignment='bottom')txt=ax.text(x,y,strings[0]+" ",color=colors[0],**kwargs)fors,cinzip(strings[1:],colors[1:]):txt=ax.annotate(s+" ",xy=(0,1),xycoords=txt,va="bottom",color=c,**kwargs)

@niranjank2022
Copy link
ContributorAuthor

Looks like just adding the space explicitly to each word (as was done previously) and not adding any offset works:

iforientation=='horizontal':txt=ax.text(x,y,strings[0]+" ",color=colors[0],**kwargs)fors,cinzip(strings[1:],colors[1:]):txt=ax.annotate(s+" ",xy=(1,0),xycoords=txt,va="bottom",color=c,**kwargs)eliforientation=='vertical':kwargs.update(rotation=90,verticalalignment='bottom')txt=ax.text(x,y,strings[0]+" ",color=colors[0],**kwargs)fors,cinzip(strings[1:],colors[1:]):txt=ax.annotate(s+" ",xy=(0,1),xycoords=txt,va="bottom",color=c,**kwargs)

Is there any link to know more about the available arguments in annotate()?

@oscargus
Copy link
Member

Is there any link to know more about the available arguments in annotate()?

https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.annotate.html#matplotlib.axes.Axes.annotate

@niranjank2022
Copy link
ContributorAuthor

Is there any link to know more about the available arguments in annotate()?

https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.annotate.html#matplotlib.axes.Axes.annotate

And also about the **kwargs arguments?

@timhoffm
Copy link
Member

image

@story645
Copy link
Member

story645 commentedJun 2, 2023
edited
Loading

Screenshot_20230602-100742.png

At the bottom of this (and should be any) parameters list, there's a link out to where the **kwargs are explained. Here the **kwargs are anything that can be passed into a Text object constructor.

@niranjank2022
Copy link
ContributorAuthor

Screenshot_20230602-100742.png

At the bottom of this (and should be any) parameters list, there's a link out to where the **kwargs are explained. Here the **kwargs are anything that can be passed into a Text object constructor.

Thanks a lot.

Copy link
Contributor

@anntzeranntzer left a comment

Choose a reason for hiding this comment

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

Looks good for now, let's move further cleanup in another PR.

niranjank2022 reacted with thumbs up emoji
@anntzeranntzer dismissedtimhoffm’sstale reviewJune 3, 2023 10:25

Spacing fixed. Thanks for pointing out the issue (leading in particular to#26028).

@anntzeranntzer merged commit5f25d20 intomatplotlib:mainJun 3, 2023
@anntzeranntzer mentioned this pull requestJun 3, 2023
5 tasks
@oscargusoscargus added this to thev3.8.0 milestoneJun 4, 2023
melissawm pushed a commit to melissawm/matplotlib that referenced this pull requestJun 15, 2023
…#25993)* Modify rainbow_text() function to use annotate() function* Add doctring* Adjust code* Add doctring for function* Remove the variable t* Modify function doctring* Modify function doctring* Remove the excess space
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@rcomerrcomerrcomer left review comments

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

@anntzeranntzeranntzer approved these changes

@timhoffmtimhoffmtimhoffm left review comments

Assignees
No one assigned
Projects
Milestone
v3.8.0
Development

Successfully merging this pull request may close these issues.

[Doc]: Rewrite rainbow_text example to use annotate()
6 participants
@niranjank2022@anntzer@oscargus@timhoffm@story645@rcomer

[8]ページ先頭

©2009-2025 Movatter.jp