From 10595be17b59d721b650201984b8368cac3c26af Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Sun, 13 Jun 2021 18:48:07 +0200 Subject: [PATCH] Improve fancyarrow_demo. Don't alphabetically sort the arrowstyles; the order of definition in the source makes more sense. (The `sorted` call was necessary back when dicts were unsorted.) Also move the definition of BracketAB after BracketA and BracketB, for consistency with the other arrow styles. Various small fixes (making the axis invisible is already done by frameon=False, no need to use mathtext). --- .../fancyarrow_demo.py | 24 +++------- lib/matplotlib/patches.py | 44 +++++++++---------- 2 files changed, 27 insertions(+), 41 deletions(-) diff --git a/examples/text_labels_and_annotations/fancyarrow_demo.py b/examples/text_labels_and_annotations/fancyarrow_demo.py index 89ce96c01083..fbaca019fdf8 100644 --- a/examples/text_labels_and_annotations/fancyarrow_demo.py +++ b/examples/text_labels_and_annotations/fancyarrow_demo.py @@ -4,8 +4,8 @@ ================================ Overview of the arrow styles available in `~.Axes.annotate`. - """ + import matplotlib.patches as mpatches import matplotlib.pyplot as plt @@ -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, @@ -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() ############################################################################# diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index 5ff6908510bf..5a92f852280d 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -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.""" @@ -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.""" pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy