8000 Document text alignment by timhoffm · Pull Request #21594 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

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

Merged
merged 1 commit into from
May 5, 2022
Merged

Conversation

timhoffm
Copy link
Member

Closes #21571.

@timhoffm timhoffm force-pushed the doc-text-positioning branch from 6859d9d to 015b397 Compare November 10, 2021 23:42
@timhoffm timhoffm added this to the v3.6.0 milestone Nov 10, 2021
@timhoffm timhoffm marked this pull request as draft November 11, 2021 07:51
@timhoffm timhoffm force-pushed the doc-text-positioning branch from 015b397 to f80688d Compare November 12, 2021 21:15
@timhoffm timhoffm force-pushed the doc-text-positioning branch 4 times, most recently from 7892681 to 234802e Compare November 24, 2021 21:29
@timhoffm timhoffm marked this pull request as ready for review November 24, 2021 21:39
8000
@@ -132,6 +132,11 @@ def __init__(self,
"""
Create a `.Text` instance at *x*, *y* with string *text*.

The text is aligned relative to the anchor point (*x*, *y*) according
to ``horizontalalingment`` (default: 'left') and ``verticalalignment``
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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::
Copy link
Member

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?

Copy link
Member Author

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.

@timhoffm timhoffm force-pushed the doc-text-positioning branch from 234802e to aa62e50 Compare December 18, 2021 21:03
import matplotlib.pyplot as plt
import numpy as np

y = [0.22, 0.34, 0.5, 0.56, 0.77]
Copy link
Member

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?

Copy link
Member Author

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)

@timhoffm timhoffm marked this pull request as draft January 4, 2022 07:32
@timhoffm timhoffm force-pushed the doc-text-positioning branch from aa62e50 to 950b9ed Compare May 1, 2022 22:49
@timhoffm
Copy link
Member Author
timhoffm commented May 1, 2022

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.

grafik

@timhoffm timhoffm marked this pull request as ready for review May 1, 2022 22:58
@timhoffm timhoffm force-pushed the doc-text-positioning branch 2 times, most recently from 0a1c39f to fa77d30 Compare May 2, 2022 23:27
@timhoffm timhoffm force-pushed the doc-text-positioning branch from fa77d30 to c0cb163 Compare May 5, 2022 20:13
Copy link
Member
@tacaswell tacaswell left a 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.

@tacaswell tacaswell merged commit c358ba5 into matplotlib:main May 5, 2022
@timhoffm timhoffm deleted the doc-text-positioning branch May 6, 2022 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Doc]: Clarify text positioning
4 participants
0