Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf1824f

Browse files
authored
Merge pull request #20430 from anntzer/fad
Improve fancyarrow_demo.
2 parents a963fb9 + 10595be commit cf1824f

File tree

2 files changed

+27
-41
lines changed

2 files changed

+27
-41
lines changed

examples/text_labels_and_annotations/fancyarrow_demo.py

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
================================
55
66
Overview of the arrow styles available in `~.Axes.annotate`.
7-
87
"""
8+
99
import matplotlib.patches as mpatches
1010
import matplotlib.pyplot as plt
1111

@@ -17,27 +17,16 @@
1717
fig = plt.figure(figsize=(4 * ncol / 1.5, figheight / 1.5))
1818
fontsize = 0.2 * 70
1919

20+
ax = fig.add_axes([0, 0, 1, 1], frameon=False)
21+
ax.set(xlim=(0, 4 * ncol), ylim=(0, figheight))
2022

21-
ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1.)
22-
23-
ax.set_xlim(0, 4 * ncol)
24-
ax.set_ylim(0, figheight)
25-
26-
27-
def to_texstring(s):
28-
s = s.replace("<", r"$<$")
29-
s = s.replace(">", r"$>$")
30-
s = s.replace("|", r"$|$")
31-
return s
32-
33-
34-
for i, (stylename, styleclass) in enumerate(sorted(styles.items())):
23+
for i, (stylename, styleclass) in enumerate(styles.items()):
3524
x = 3.2 + (i // nrow) * 4
3625
y = (figheight - 0.7 - i % nrow) # /figheight
3726
p = mpatches.Circle((x, y), 0.2)
3827
ax.add_patch(p)
3928

40-
ax.annotate(to_texstring(stylename), (x, y),
29+
ax.annotate(stylename, (x, y),
4130
(x - 1.2, y),
4231
ha="right", va="center",
4332
size=fontsize,
@@ -50,9 +39,6 @@ def to_texstring(s):
5039
),
5140
bbox=dict(boxstyle="square", fc="w"))
5241

53-
ax.xaxis.set_visible(False)
54-
ax.yaxis.set_visible(False)
55-
5642
plt.show()
5743

5844
#############################################################################

lib/matplotlib/patches.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3466,28 +3466,6 @@ def transmute(self, path, mutation_size, linewidth):
34663466

34673467
return p, False
34683468

3469-
@_register_style(_style_list, name="]-[")
3470-
class BracketAB(_Bracket):
3471-
"""An arrow with outward square brackets at both ends."""
3472-
3473-
def __init__(self,
3474-
widthA=1., lengthA=0.2, angleA=0,
3475-
widthB=1., lengthB=0.2, angleB=0):
3476-
"""
3477-
Parameters
3478-
----------
3479-
widthA, widthB : float, default: 1.0
3480-
Width of the bracket.
3481-
lengthA, lengthB : float, default: 0.2
3482-
Length of the bracket.
3483-
angleA, angleB : float, default: 0 degrees
3484-
Orientation of the bracket, as a counterclockwise angle.
3485-
0 degrees means perpendicular to the line.
3486-
"""
3487-
super().__init__(True, True,
3488-
widthA=widthA, lengthA=lengthA, angleA=angleA,
3489-
widthB=widthB, lengthB=lengthB, angleB=angleB)
3490-
34913469
@_register_style(_style_list, name="]-")
34923470
class BracketA(_Bracket):
34933471
"""An arrow with an outward square bracket at its start."""
@@ -3526,6 +3504,28 @@ def __init__(self, widthB=1., lengthB=0.2, angleB=None):
35263504
super().__init__(None, True,
35273505
widthB=widthB, lengthB=lengthB, angleB=angleB)
35283506

3507+
@_register_style(_style_list, name="]-[")
3508+
class BracketAB(_Bracket):
3509+
"""An arrow with outward square brackets at both ends."""
3510+
3511+
def __init__(self,
3512+
widthA=1., lengthA=0.2, angleA=0,
3513+
widthB=1., lengthB=0.2, angleB=0):
3514+
"""
3515+
Parameters
3516+
----------
3517+
widthA, widthB : float, default: 1.0
3518+
Width of the bracket.
3519+
lengthA, lengthB : float, default: 0.2
3520+
Length of the bracket.
3521+
angleA, angleB : float, default: 0 degrees
3522+
Orientation of the bracket, as a counterclockwise angle.
3523+
0 degrees means perpendicular to the line.
3524+
"""
3525+
super().__init__(True, True,
3526+
widthA=widthA, lengthA=lengthA, angleA=angleA,
3527+
widthB=widthB, lengthB=lengthB, angleB=angleB)
3528+
35293529
@_register_style(_style_list, name="|-|")
35303530
class BarAB(_Bracket):
35313531
"""An arrow with vertical bars ``|`` at both ends."""

0 commit comments

Comments
 (0)