-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Clean up and move text rotation example #8066
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
Text rotation demonstration | ||
=========================== | ||
|
||
The way matplotlib does text layout is counter-intuitive to some, so |
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.
Maybe we could be a little gentler about this. Something like, "matplotlib takes a different approach to text layout..." (maybe?)
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.
matplotlib -> Matplotlib
aligned by it's bounding box (the rectangular box that surrounds the | ||
ink rectangle). The order of operations is rotation then | ||
alignment, rather than alignment then rotation. Basically, the text | ||
is centered at your x,y location, rotated around this point, and then |
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.
is this true with e.g., rotation_mode='anchor' and ha='right'
?
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 probably not.
It might be worth having an example for the default rotation mode (this example), and an example for the 'anchor'
rotation mode (to replace http://matplotlib.org/devdocs/examples/pylab_examples/demo_text_rotation_mode.html)
ax.text(4.5, 0.5, 'text -45', props, rotation=-45) | ||
ax.set_yticks([0, .5, 1]) | ||
ax.set_xlim(0, 5) | ||
ax.grid(True) |
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.
Would love to see some of the different rotation modes in this example similar to this: http://matplotlib.org/devdocs/examples/pylab_examples/demo_text_rotation_mode.html
Text rotation demonstration | ||
=========================== | ||
|
||
The way matplotlib does text layout is counter-intuitive to some, so |
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.
matplotlib -> Matplotlib
|
||
The way matplotlib does text layout is counter-intuitive to some, so | ||
this example is designed to make it a little clearer. The text is | ||
aligned by it's bounding box (the rectangular box that surrounds the |
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.
it's -> its
I've tidied up the docstring, and also scattered the text anchor points which I think makes the demo easier to understand. Does anyone have any thoughts on leaving this as a demo of the default text rotation demonstration, and replacing http://matplotlib.org/devdocs/examples/pylab_examples/demo_text_rotation_mode.html with a demo of the |
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.
LGTM 👍
I would just remove pylab_examples/demo_text_rotation_mode.py. |
I gave my approval, but it'd be nice before we merged this one if you could do a small summary of all related examples in the gallery (ie, text rotation examples) and to merge and delete as many as possible. |
Can someone else review this? I think this patch is ready to be merged, but it requires an extra review. |
|
||
|
||
def addtext(ax, props): | ||
ax.text(0.5, 0.5, 'text 0', props, rotation=0) |
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.
How about putting this in the loop too? for i, angle in enumerate([0, 45, 135, 225, -45]):
import numpy as np | ||
|
||
|
||
def addtext(ax, props): |
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 function does more than just add text.
fig, axs = plt.subplots(2, 1) | ||
|
||
addtext(axs[0], {'ha': 'center', 'va': 'center', 'bbox': bbox}) | ||
axs[0].set_xticks(np.arange(0, 5.1, 0.5), []) |
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 could be done in the (suitably-renamed) addtext
.
@QuLogic This PR modifies the docstring. The code was there before and @dstansby did not modify it. |
Only the docstring was modified, but that was enough for github to consider this not as a move, but as a deletion + modification.. @dstansby Let us know if you'd like to fix the core content of the example, or whether you'd rather have this merged as-is. |
Hello, I would prefer this to be merged as is - I only intended it to be a MEP-12 clean and a move, and if anyone wants to change what the example does they can always open another PR. |
No description provided.