Skip to content

Commit f741491

Browse files
story645rcomer
andcommitted
blended artist + fixing header + redirects/deletes
Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com>
1 parent 54f1612 commit f741491

File tree

4 files changed

+57
-97
lines changed

4 files changed

+57
-97
lines changed

doc/users/prev_whats_new/whats_new_3.1.0.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,8 @@ changed.
179179
Alternatively to strings like ``"data"`` or ``"axes fraction"``,
180180
`.ConnectionPatch` now accepts any `~matplotlib.transforms.Transform` as input
181181
for the *coordsA* and *coordsB* arguments. This allows to draw lines between
182-
points defined in different user defined coordinate systems. Also see the
183-
:doc:`Connect Simple01 example </gallery/userdemo/connect_simple01>`.
184-
182+
points defined in different user defined coordinate systems. Also see
183+
:ref:`using_connectionpatch`.
185184

186185
mplot3d Line3D now allows {set,get}_data_3d
187186
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

galleries/examples/userdemo/annotate_simple_coord02.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

galleries/examples/userdemo/connect_simple01.py

Lines changed: 0 additions & 52 deletions
This file was deleted.

galleries/users_explain/text/annotations.py

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
.. redirect-from:: /gallery/userdemo/annotate_simple04
66
.. redirect-from:: /gallery/userdemo/anchored_box04
77
.. redirect-from:: /gallery/userdemo/annotate_simple_coord01
8+
.. redirect-from:: /gallery/userdemo/annotate_simple_coord02
89
.. redirect-from:: /gallery/userdemo/annotate_simple_coord03
10+
.. redirect-from:: /gallery/userdemo/connect_simple01
911
.. redirect-from:: /tutorials/text/annotations
1012
1113
.. _annotations:
@@ -85,7 +87,7 @@
8587
# .. _annotation-data:
8688
#
8789
# Annotating data
88-
# ~~~~~~~~~~~~~~~
90+
# ^^^^^^^^^^^^^^^
8991
#
9092
# This example places the text coordinates in fractional axes coordinates:
9193

@@ -104,7 +106,7 @@
104106
# %%
105107
#
106108
# Annotating an Artist
107-
# ~~~~~~~~~~~~~~~~~~~~
109+
# ^^^^^^^^^^^^^^^^^^^^
108110
#
109111
# Annotations can be positioned relative to an `.Artist` instance by passing
110112
# that Artist in as *xycoords*. Then *xy* is interpreted as a fraction of the
@@ -131,7 +133,7 @@
131133
# .. _annotation-with-arrow:
132134
#
133135
# Annotating with arrows
134-
# ~~~~~~~~~~~~~~~~~~~~~~
136+
# ^^^^^^^^^^^^^^^^^^^^^^
135137
#
136138
# You can enable drawing of an arrow from the text to the annotated point
137139
# by giving a dictionary of arrow properties in the optional keyword
@@ -181,7 +183,7 @@
181183
# .. _annotations-offset-text:
182184
#
183185
# Placing text annotations relative to data
184-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
186+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
185187
#
186188
# Annotations can be positioned at a relative offset to the *xy* input to
187189
# annotation by setting the *textcoords* keyword argument to ``'offset points'``
@@ -210,7 +212,7 @@
210212
# and :func:`~matplotlib.pyplot.annotate` before reading this section.
211213
#
212214
# Annotating with boxed text
213-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
215+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^
214216
#
215217
# `~.Axes.text` takes a *bbox* keyword argument, which draws a box around the
216218
# text:
@@ -261,7 +263,7 @@
261263
#
262264
#
263265
# Defining custom box styles
264-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~
266+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^
265267
#
266268
# You can use a custom box style. The value for the ``boxstyle`` can be a
267269
# callable object in the following forms:
@@ -307,7 +309,7 @@ def custom_box_style(x0, y0, width, height, mutation_size):
307309
# .. _annotation_with_custom_arrow:
308310
#
309311
# Customizing annotation arrows
310-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
312+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
311313
#
312314
# An arrow connecting *xy* to *xytext* can be optionally drawn by
313315
# specifying the *arrowprops* argument. To draw only an arrow, use
@@ -446,7 +448,7 @@ def custom_box_style(x0, y0, width, height, mutation_size):
446448

447449
# %%
448450
# Placing Artist at anchored Axes locations
449-
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
451+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
450452
#
451453
# There are classes of artists that can be placed at an anchored
452454
# location in the Axes. A common example is the legend. This type
@@ -562,11 +564,15 @@ def custom_box_style(x0, y0, width, height, mutation_size):
562564
# examples in :ref:`annotations-tutorial` used the ``data`` coordinate system;
563565
# Some others more advanced options are:
564566
#
565-
# 1. A `.Transform` instance. For more information on transforms, see the
566-
# :ref:`transforms_tutorial` For example, the
567-
# ``Axes.transAxes`` transform positions the annotation relative to the Axes
568-
# coordinates and using it is therefore identical to setting the
569-
# coordinate system to "axes fraction":
567+
# `.Transform` instance
568+
# ^^^^^^^^^^^^^^^^^^^^^
569+
#
570+
# Transforms map coordinates into different coordinate systems, usually the
571+
# display coordinate system. See :ref:`transforms_tutorial` for a detailed
572+
# explanation. Here Transform objects are used to identify the coordinate
573+
# system of the corresponding points. For example, the ``Axes.transAxes``
574+
# transform positions the annotation relative to the Axes coordinates; therefore
575+
# using it is identical to setting the coordinate system to "axes fraction":
570576

571577
fig, (ax1, ax2) = plt.subplots(nrows=1, ncols=2, figsize=(6, 3))
572578
ax1.annotate("Test", xy=(0.2, 0.2), xycoords=ax1.transAxes)
@@ -592,8 +598,11 @@ def custom_box_style(x0, y0, width, height, mutation_size):
592598
# %%
593599
# .. _artist_annotation_coord:
594600
#
595-
# 2. An `.Artist` instance. The *xy* value (or *xytext*) is interpreted as a
596-
# fractional coordinate of the bounding box (bbox) of the artist:
601+
# `.Artist` instance
602+
# ^^^^^^^^^^^^^^^^^^
603+
#
604+
# The *xy* value (or *xytext*) is interpreted as a fractional coordinate of the
605+
# bounding box (bbox) of the artist:
597606

598607
fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(3, 3))
599608
an1 = ax.annotate("Test 1",
@@ -614,7 +623,10 @@ def custom_box_style(x0, y0, width, height, mutation_size):
614623
# that *an2* needs to be drawn after *an1*. The base class for all bounding
615624
# boxes is `.BboxBase`
616625
#
617-
# 3. A callable object that takes the renderer instance as single argument, and
626+
# Callable that returns `.Transform` of `.BboxBase`
627+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
628+
#
629+
# A callable object that takes the renderer instance as single argument, and
618630
# returns either a `.Transform` or a `.BboxBase`. For example, the return
619631
# value of `.Artist.get_window_extent` is a bbox, so this method is identical
620632
# to (2) passing in the artist:
@@ -642,7 +654,10 @@ def custom_box_style(x0, y0, width, height, mutation_size):
642654
an2 = ax2.annotate("Test 2", xy=(0.5, 0.5), xycoords=ax2.get_window_extent)
643655

644656
# %%
645-
# 4. A blended pair of coordinate specifications -- the first for the
657+
# Blended coordinate specification
658+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
659+
#
660+
# A blended pair of coordinate specifications -- the first for the
646661
# x-coordinate, and the second is for the y-coordinate. For example, x=0.5 is
647662
# in data coordinates, and y=1 is in normalized axes coordinates:
648663

@@ -652,7 +667,22 @@ def custom_box_style(x0, y0, width, height, mutation_size):
652667
ax.set(xlim=(0, 2), ylim=(1, 2))
653668

654669
# %%
655-
# 5. Sometimes, you want your annotation with some "offset points", not from the
670+
# Any of the supported coordinate systems can be used in a blended
671+
# specification. For example, the text "Anchored to 1 & 2" is positioned
672+
# relative to the two `.Text` Artists:
673+
674+
fig, ax = plt.subplots(figsize=(3, 3))
675+
676+
t1 = ax.text(0.05, .05, "Text 1", va='bottom', ha='left')
677+
t2 = ax.text(0.90, .90, "Text 2", ha='right')
678+
t3 = ax.annotate("Anchored to 1 & 2", xy=(0, 0), xycoords=(t1, t2),
679+
va='bottom', color='tab:orange',)
680+
681+
# %%
682+
# `.text.OffsetFrom`
683+
# ^^^^^^^^^^^^^^^^^^
684+
#
685+
# Sometimes, you want your annotation with some "offset points", not from the
656686
# annotated point but from some other point or artist. `.text.OffsetFrom` is
657687
# a helper for such cases.
658688

@@ -672,8 +702,13 @@ def custom_box_style(x0, y0, width, height, mutation_size):
672702
arrowprops=dict(arrowstyle="->"))
673703

674704
# %%
705+
# Non-text annotations
706+
# --------------------
707+
#
708+
# .. _using_connectionpatch:
709+
#
675710
# Using ConnectionPatch
676-
# ~~~~~~~~~~~~~~~~~~~~~
711+
# ^^^^^^^^^^^^^^^^^^^^^
677712
#
678713
# `.ConnectionPatch` is like an annotation without text. While `~.Axes.annotate`
679714
# is sufficient in most situations, `.ConnectionPatch` is useful when you want
@@ -698,7 +733,7 @@ def custom_box_style(x0, y0, width, height, mutation_size):
698733
# for positioning the axes.
699734
#
700735
# Zoom effect between Axes
701-
# ~~~~~~~~~~~~~~~~~~~~~~~~
736+
# ^^^^^^^^^^^^^^^^^^^^^^^^
702737
#
703738
# `mpl_toolkits.axes_grid1.inset_locator` defines some patch classes useful for
704739
# interconnecting two axes.

0 commit comments

Comments
 (0)