Repository navigation
Modify rainbow_text() function to use annotate() function - #25993
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.
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.
Please leave the docstring in place.
| 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.
you can directly do txt = annotate() even if you use the previous value of txt as parameter.
There was a problem hiding this comment.
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. |
|
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? |
anntzer
left a comment
There was a problem hiding this comment.
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