Skip to content

Further cleanup rainbow_text example. #26057

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
Jun 4, 2023
Merged

Further cleanup rainbow_text example. #26057

merged 1 commit into from
Jun 4, 2023

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Jun 3, 2023

Share more code between horizontal and vertical cases.

Show that x, y can use any transform (as for any text() call).

Standardize docs of "extra" properties.

Small doc rewordings.

followup to #25993.

PR summary

PR checklist

@timhoffm
Copy link
Member

timhoffm commented Jun 3, 2023

I don't like the visual appearance now:

  • font sizes are too different
  • there's a lot of unused vertical space on the Axes
  • the figure text is too close to the xticklabels
  • the figure text stands out quite a bit on the left side, which looks imbalanced

image

General notes:

  • Do we still need the "History" note? I think the example code has moved from the original code and it does not add value to the user.
  • Are the orientation parameter and the transform example worth the added complexity? The main purpose of the example is to show that you can line up texts using annotate(). That could be done in a couple of lines without a dedicated function.
  • We should explain the positioning mechanism (annotate the previous Text object).

@anntzer
Copy link
Contributor Author

anntzer commented Jun 3, 2023

Good points all around. I streamlined the whole thing; how does that look to you?

Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

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

in code suggestions:

  • Parameter name c -> color for readability
  • increase font size to make the text more prominent (in particular also in the thumbnail

Can we rename the example? "Rainbow text" is not quite instructive. Either to the purpose "Complex test formatting" (with the nuissance that this is a hackish solution when selling it as text formatting) or to the technical solution "Concatenating text object". Other titles welcome.

fig, ax = plt.subplots()

# The first word, created with text().
text = ax.text(.1, .5, "Matplotlib", c="red")
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
text = ax.text(.1, .5, "Matplotlib", c="red")
text = ax.text(.1, .5, "Matplotlib", color="red", fontsize=20)

Comment on lines 22 to 23
" says,", xycoords=text, xy=(1, 0), verticalalignment="bottom",
c="gold", weight="bold", # custom properties
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
" says,", xycoords=text, xy=(1, 0), verticalalignment="bottom",
c="gold", weight="bold", # custom properties
" says,", xycoords=text, xy=(1, 0), verticalalignment="bottom", fontsize=20,
color="gold", weight="bold", # custom properties

Comment on lines 26 to 27
" hello", xycoords=text, xy=(1, 0), verticalalignment="bottom",
c="green", style="italic", # custom properties
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
" hello", xycoords=text, xy=(1, 0), verticalalignment="bottom",
c="green", style="italic", # custom properties
" hello", xycoords=text, xy=(1, 0), verticalalignment="bottom", fontsize=20,
color="green", style="italic", # custom properties

Comment on lines 30 to 31
" world!", xycoords=text, xy=(1, 0), verticalalignment="bottom",
c="blue", family="serif", # custom properties
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
" world!", xycoords=text, xy=(1, 0), verticalalignment="bottom",
c="blue", family="serif", # custom properties
" world!", xycoords=text, xy=(1, 0), verticalalignment="bottom", fontsize=20,
color="blue", family="serif", # custom properties

Comment on lines 7 to 10
(e.g., color or font), positioning each one after the other: each Text other
than the first one created with `~.Axes.annotate` and positioned so that its
lower left corner is at the lower right corner (``xy=(1, 0)``) of the previous
one (``xycoords=text``).
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
(e.g., color or font), positioning each one after the other: each Text other
than the first one created with `~.Axes.annotate` and positioned so that its
lower left corner is at the lower right corner (``xy=(1, 0)``) of the previous
one (``xycoords=text``).
(e.g., color or font), positioning each one after the other: The first Text is
directly created using `~.Axes.text`. All subsequent Texts are created with
`~.Axes.annotate`, which allows positioning so that its lower left corner is at
the lower right corner (``xy=(1, 0)``) of the previous one (``xycoords=text``).

@anntzer
Copy link
Contributor Author

anntzer commented Jun 4, 2023

Sure, done.

@timhoffm timhoffm merged commit 449caf7 into matplotlib:main Jun 4, 2023
@anntzer anntzer deleted the rt branch June 4, 2023 16:20
@oscargus oscargus added this to the v3.8.0 milestone Jun 4, 2023
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.

3 participants