-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Document text alignment #21594
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
Document text alignment #21594
Conversation
6859d9d
to
015b397
Compare
015b397
to
f80688d
Compare
7892681
to
234802e
Compare
lib/matplotlib/text.py
Outdated
@@ -132,6 +132,11 @@ def __init__(self, | |||
""" | |||
Create a `.Text` instance at *x*, *y* with string *text*. | |||
|
|||
8000 | The text is aligned relative to the anchor point (*x*, *y*) according | ||
to ``horizontalalingment`` (default: 'left') and ``verticalalignment`` |
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.
to ``horizontalalingment`` (default: 'left') and ``verticalalignment`` | |
to ``horizontalalignment`` (default: 'left') and ``verticalalignment`` |
Texts are aligned relative to their anchor point depending on the properties | ||
``horizontalalignment`` and ``verticalalignment``. | ||
|
||
.. plot:: |
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.
Why put this in a plot directive instead of in the example itself?
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.
Because we only care about the graphic, the code is irrelevant in this context. The plot directive hides the code.
234802e
to
aa62e50
Compare
import matplotlib.pyplot as plt | ||
import numpy as np | ||
|
||
y = [0.22, 0.34, 0.5, 0.56, 0.77] |
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.
The top line appears a bit low; did using the inverse transforms not work out?
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.
No the inverse does not work. See #21594 (comment)
aa62e50
to
950b9ed
Compare
I'd like to get this in as is. The hard-coded guidance lines are not so nice, but I failed to calculate their positions (maybe it's because I have a hidpi scaling?). Anyway I don't want to spend more time on this. I think this is still very helpful even if the lines are not pixel-perfect. Of course, if somebody wants to dig into the calculation, that'd be more than welcome, but could also be a follow-up improvement. |
0a1c39f
to
fa77d30
Compare
fa77d30
to
c0cb163
Compare
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 this will survive hi-dpi issues as the figure (and hence Axes) is of a fixed size (in inches), the data limits are always the same, and the text is a fixed size in inches, thus at any DPI the parts of the text will fall at the same place in data coordinates.
I suspect if we placed the points / labels in a physical unit stack farther down (up)? the transform chain we could place them all in points but this works, the point in the image so merging as-is.
Closes #21571.