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

Skip to content

Improve fancyarrow_demo. #20430

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 13, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
24 changes: 5 additions & 19 deletions examples/text_labels_and_annotations/fancyarrow_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
================================

Overview of the arrow styles available in `~.Axes.annotate`.

"""

import matplotlib.patches as mpatches
import matplotlib.pyplot as plt

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

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

ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1.)

ax.set_xlim(0, 4 * ncol)
ax.set_ylim(0, figheight)


def to_texstring(s):
s = s.replace("<", r"$<$")
s = s.replace(">", r"$>$")
s = s.replace("|", r"$|$")
return s


for i, (stylename, styleclass) in enumerate(sorted(styles.items())):
for i, (stylename, styleclass) in enumerate(styles.items()):
x = 3.2 + (i // nrow) * 4
y = (figheight - 0.7 - i % nrow) # /figheight
p = mpatches.Circle((x, y), 0.2)
ax.add_patch(p)

ax.annotate(to_texstring(stylename), (x, y),
ax.annotate(stylename, (x, y),
(x - 1.2, y),
ha="right", va="center",
size=fontsize,
Expand All @@ -50,9 +39,6 @@ def to_texstring(s):
),
bbox=dict(boxstyle="square", fc="w"))

ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)

plt.show()

#############################################################################
Expand Down
44 changes: 22 additions & 22 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -3466,28 +3466,6 @@ def transmute(self, path, mutation_size, linewidth):

return p, False

@_register_style(_style_list, name="]-[")
class BracketAB(_Bracket):
"""An arrow with outward square brackets at both ends."""

def __init__(self,
widthA=1., lengthA=0.2, angleA=0,
widthB=1., lengthB=0.2, angleB=0):
"""
Parameters
----------
widthA, widthB : float, default: 1.0
Width of the bracket.
lengthA, lengthB : float, default: 0.2
Length of the bracket.
angleA, angleB : float, default: 0 degrees
Orientation of the bracket, as a counterclockwise angle.
0 degrees means perpendicular to the line.
"""
super().__init__(True, True,
widthA=widthA, lengthA=lengthA, angleA=angleA,
widthB=widthB, lengthB=lengthB, angleB=angleB)

@_register_style(_style_list, name="]-")
class BracketA(_Bracket):
"""An arrow with an outward square bracket at its start."""
Expand Down Expand Up @@ -3526,6 +3504,28 @@ def __init__(self, widthB=1., lengthB=0.2, angleB=None):
super().__init__(None, True,
widthB=widthB, lengthB=lengthB, angleB=angleB)

@_register_style(_style_list, name="]-[")
class BracketAB(_Bracket):
"""An arrow with outward square brackets at both ends."""

def __init__(self,
widthA=1., lengthA=0.2, angleA=0,
widthB=1., lengthB=0.2, angleB=0):
"""
Parameters
----------
widthA, widthB : float, default: 1.0
Width of the bracket.
lengthA, lengthB : float, default: 0.2
Length of the bracket.
angleA, angleB : float, default: 0 degrees
Orientation of the bracket, as a counterclockwise angle.
0 degrees means perpendicular to the line.
"""
super().__init__(True, True,
widthA=widthA, lengthA=lengthA, angleA=angleA,
widthB=widthB, lengthB=lengthB, angleB=angleB)

@_register_style(_style_list, name="|-|")
class BarAB(_Bracket):
"""An arrow with vertical bars ``|`` at both ends."""
Expand Down