Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

ENH: fig.annotate#28753

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
story645 wants to merge1 commit intomatplotlib:main
base:main
Choose a base branch
Loading
fromstory645:rainbow-fig
Draft
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@
import matplotlib.pyplot as plt

plt.rcParams["font.size"] = 20

ax = plt.figure().add_subplot(xticks=[], yticks=[])

# The first word, created with text().
Expand All@@ -29,3 +30,42 @@
color="blue", family="serif") # custom properties

plt.show()

# %%
#
# Figure Text
# -----------
#
# Figure text can be concatenated in a similar manner by creating a `~.text.Annotation`
# object and adding it to the figure:


import matplotlib.text as mtext

Check failure on line 43 in galleries/examples/text_labels_and_annotations/rainbow_text.py

View workflow job for this annotation

GitHub Actions/ flake8

[flake8] reported by reviewdog 🐶E402 module level import not at top of fileRaw Output:./galleries/examples/text_labels_and_annotations/rainbow_text.py:43:1: E402 module level import not at top of file

fig, ax = plt.subplots(subplot_kw=dict(visible=False))

text = fig.text(.1, .5, "Matplotlib", color="red")

text = mtext.Annotation(" says,", xycoords=text, xy=(1, 0),
va="bottom", color="gold", weight="bold")
fig.add_artist(text) # manually add artist to figure

text = mtext.Annotation(" hello", xycoords=text, xy=(1, 0),
va="bottom", color="green", style="italic")
fig.add_artist(text)

text = mtext.Annotation(" world!", xycoords=text, xy=(1, 0),
va="bottom", color="blue", family="serif")
fig.add_artist(text)

# %%
#
# .. admonition:: References
#
# The use of the following functions, methods, classes and modules is shown
# in this example:
#
# - `matplotlib.axes.Axes.annotate`
# - `matplotlib.text.Annotation`
#
# .. tags:: component: annotation, component: text, styling: color
30 changes: 30 additions & 0 deletionsgalleries/users_explain/text/annotations.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -586,7 +586,37 @@ def __call__(self, x0, y0, width, height, mutation_size):
connectionstyle="arc3,rad=-0.2",
relpos=(1., 0.),
fc="w"))
# %%
# Create Annotation Artist
# ^^^^^^^^^^^^^^^^^^^^^^^^
#
# An annotation artist may also be created using `.text.Annotation` and then added to
# the figure. This can be used to annotate other artists that are added to directly
# to the figure. For example:

import matplotlib.patches as mpatches
import matplotlib.text as mtext

fig, ax = plt.subplots(subplot_kw=dict(visible=False), figsize=(3, 3))

# add a circle and a square
circle = mpatches.Circle((.25, .75), radius=.15, fc='gold', ec='navy')
fig.add_artist(circle)
square = mpatches.Rectangle((.75, .25), height=.25, width=.25, fc='navy', ec='gold')
fig.add_artist(square)

# position annotation line between both artists
con = mtext.Annotation("", xy=(.95, .25), xytext=(0, 1),
xycoords=circle, textcoords=square,
arrowprops=dict(arrowstyle="-", lw=3, ls='--', color='navy'))
fig.add_artist(con)

# Position text relative to annotation
label = mtext.Annotation("connection", xy=(.5, .5), xytext=(1, 1),
xycoords=con, textcoords=fig.transFigure,
arrowprops=dict(arrowstyle="->", lw=3, ls=':', color='gold'),
size=20, color='navy', va='top', ha='right')
fig.add_artist(label)
# %%
# Placing Artist at anchored Axes locations
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
1 change: 1 addition & 0 deletionspyproject.toml
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -179,6 +179,7 @@ convention = "numpy"
"galleries/examples/style_sheets/bmh.py" = ["E501"]
"galleries/examples/subplots_axes_and_figures/demo_constrained_layout.py" = ["E402"]
"galleries/examples/text_labels_and_annotations/custom_legends.py" = ["E402"]
"galleries/examples/text_labels_and_annotations/rainbow_text.py" = ["E402"]
"galleries/examples/ticks/date_concise_formatter.py" = ["E402"]
"galleries/examples/ticks/date_formatters_locators.py" = ["F401"]
"galleries/examples/user_interfaces/embedding_in_gtk3_panzoom_sgskip.py" = ["E402"]
Expand Down
Loading

[8]ページ先頭

©2009-2025 Movatter.jp