-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Please tell whether my code is correct or anything can be changed. After that, I will work on documentation. |
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.
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 us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code 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 |
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.
Please leave the docstring in place.
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.
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:]): |
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.
you can directly do txt = annotate()
even if you use the previous value of txt as parameter.
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 think I have done it now.
The idea is correct. As noted by @timhoffm the code/docs simply needs to be cleaned up now. |
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.
This introduces larger (unnatural) spacing.
@anntzer maybe you can comment on this as the use of annotate()
is your proposal.
Looks like just adding the space explicitly to each word (as was done previously) and not adding any offset works: if orientation == 'horizontal':
txt = ax.text(x, y, strings[0] + " ", color=colors[0], **kwargs)
for s, c in zip(strings[1:], colors[1:]):
txt = ax.annotate(s + " ", xy=(1, 0), xycoords=txt,
va="bottom", color=c, **kwargs)
elif orientation == 'vertical':
kwargs.update(rotation=90, verticalalignment='bottom')
txt = ax.text(x, y, strings[0] + " ", color=colors[0], **kwargs)
for s, c in zip(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()? |
|
And also about the **kwargs arguments? |
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.
Looks good for now, let's move further cleanup in another PR.
Spacing fixed. Thanks for pointing out the issue (leading in particular to #26028).
…#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
PR summary
This pull request is to modify the rainbow_text() function to use annotate() method. Closes #25941
PR checklist