From b4b57b1271b0075d3b34fbfb3ea476fb8f2d35ea Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Wed, 15 Dec 2021 19:56:37 +0100 Subject: [PATCH] Revert "DOC: update anatomy of figure" --- examples/showcase/anatomy.py | 141 +++++++++++++++++------------------ 1 file changed, 67 insertions(+), 74 deletions(-) diff --git a/examples/showcase/anatomy.py b/examples/showcase/anatomy.py index 5f292c15d41e..cc3f334c0987 100644 --- a/examples/showcase/anatomy.py +++ b/examples/showcase/anatomy.py @@ -6,18 +6,10 @@ This figure shows the name of several matplotlib elements composing a figure """ - import numpy as np import matplotlib.pyplot as plt -from matplotlib.patches import Circle, Rectangle -from matplotlib.patheffects import withStroke from matplotlib.ticker import AutoMinorLocator, MultipleLocator -royal_blue = "#002082" -royal_blue = [0, 20/256, 82/256] - -# make the figure - np.random.seed(19680801) X = np.linspace(0.5, 3.5, 100) @@ -25,10 +17,8 @@ Y2 = 1+np.cos(1+X/0.75)/2 Y3 = np.random.uniform(Y1, Y2, len(X)) -fig = plt.figure(figsize=(8, 8), facecolor='1') -marg = 0.15 -ax = fig.add_axes([marg, marg, 1-1.8*marg, 1-1.8*marg], aspect=1, - facecolor='1') +fig = plt.figure(figsize=(8, 8)) +ax = fig.add_subplot(1, 1, 1, aspect=1) def minor_tick(x, pos): @@ -46,107 +36,110 @@ def minor_tick(x, pos): ax.set_xlim(0, 4) ax.set_ylim(0, 4) -ax.tick_params(which='major', width=1.0, labelsize=14) -ax.tick_params(which='major', length=10, labelsize=14) +ax.tick_params(which='major', width=1.0) +ax.tick_params(which='major', length=10) ax.tick_params(which='minor', width=1.0, labelsize=10) ax.tick_params(which='minor', length=5, labelsize=10, labelcolor='0.25') ax.grid(linestyle="--", linewidth=0.5, color='.25', zorder=-10) -ax.plot(X, Y1, c='C0', lw=2.5, label="Blue signal", zorder=10) -ax.plot(X, Y2, c='C1', lw=2.5, label="Orange signal") -ax.plot(X[::3], Y3[::3], linewidth=0, markersize=9, - marker='s', markerfacecolor='none', markeredgecolor='C4', - markeredgewidth=2.5) +ax.plot(X, Y1, c=(0.25, 0.25, 1.00), lw=2, label="Blue signal", zorder=10) +ax.plot(X, Y2, c=(1.00, 0.25, 0.25), lw=2, label="Red signal") +ax.plot(X, Y3, linewidth=0, + marker='o', markerfacecolor='w', markeredgecolor='k') ax.set_title("Anatomy of a figure", fontsize=20, verticalalignment='bottom') -ax.set_xlabel("x Axis label", fontsize=14) -ax.set_ylabel("y Axis label", fontsize=14) - -ax.legend(loc="upper right", fontsize=14) +ax.set_xlabel("X axis label") +ax.set_ylabel("Y axis label") -# Annotate the figure +ax.legend(loc="upper right") -def just_circle(x, y, radius=0.15): - c = Circle((x, y), radius, clip_on=False, zorder=10, linewidth=2.5, - edgecolor=royal_blue + [0.6], facecolor='none', - path_effects=[withStroke(linewidth=7, foreground=(1, 1, 1, 1))]) - ax.add_artist(c) +def circle(x, y, radius=0.15): + from matplotlib.patches import Circle + from matplotlib.patheffects import withStroke + circle = Circle((x, y), radius, clip_on=False, zorder=10, linewidth=1, + edgecolor='black', facecolor=(0, 0, 0, .0125), + path_effects=[withStroke(linewidth=5, foreground='w')]) + ax.add_artist(circle) def text(x, y, text): - ax.text(x, y, text, zorder=100, - ha='center', va='top', weight='bold', color=royal_blue, - style='italic', fontfamily='monospace', - path_effects=[withStroke(linewidth=7, foreground=(1, 1, 1, 1))]) - - -def code(x, y, text): - ax.text(x, y, text, zorder=100, - ha='center', va='top', weight='normal', color='0.0', - fontfamily='Courier New', fontsize='medium', - path_effects=[withStroke(linewidth=7, foreground=(1, 1, 1, 1))]) - + ax.text(x, y, text, backgroundcolor="white", + ha='center', va='top', weight='bold', color='blue') -def circle(x, y, txt, cde, radius=0.15): - just_circle(x, y, radius=radius) - text(x, y-0.2, txt) - code(x, y-0.33, cde) -# Minor tick label -circle(3.25, -0.10, "Minor tick label", - "ax.xaxis.set_minor_formatter") +# Minor tick +circle(0.50, -0.10) +text(0.50, -0.32, "Minor tick label") # Major tick -circle(-0.03, 1.05, "Major tick", "ax.yaxis.set_major_locator") +circle(-0.03, 4.00) +text(0.03, 3.80, "Major tick") # Minor tick -y = 3.75 -circle(0.00, 3.75, "Minor tick", "ax.yaxis.set_minor_locator") +circle(0.00, 3.50) +text(0.00, 3.30, "Minor tick") # Major tick label -circle(-0.15, 3.00, "Major tick label", "ax.yaxis.set_major_formatter") +circle(-0.15, 3.00) +text(-0.15, 2.80, "Major tick label") # X Label -circle(1.90, -0.32, "xlabel", "ax.set_xlabel") +circle(1.80, -0.27) +text(1.80, -0.45, "X axis label") # Y Label -circle(-0.27, 1.68, "ylabel", "ax.set_ylabel") +circle(-0.27, 1.80) +text(-0.27, 1.6, "Y axis label") # Title -circle(1.58, 4.13, "Title", "ax.set_title") +circle(1.60, 4.13) +text(1.60, 3.93, "Title") # Blue plot -circle(1.75, 2.80, "Line", "ax.plot") +circle(1.75, 2.80) +text(1.75, 2.60, "Line\n(line plot)") + +# Red plot +circle(1.20, 0.60) +text(1.20, 0.40, "Line\n(line plot)") # Scatter plot -circle(2.25, 1.54, "Markers", "ax.scatter") +circle(3.20, 1.75) +text(3.20, 1.55, "Markers\n(scatter plot)") # Grid -circle(3.00, 3.00, "Grid", "ax.grid") +circle(3.00, 3.00) +text(3.00, 2.80, "Grid") # Legend -circle(3.60, 3.65, "Legend", "ax.legend") +circle(3.70, 3.80) +text(3.70, 3.60, "Legend") # Axes -circle(2.5, 0.55, "Axes", "fig.subplots") +circle(0.5, 0.5) +text(0.5, 0.3, "Axes") # Figure -circle(4.185, 4.3, "Figure", "plt.figure") - -# x Axis -circle(0.65, 0.01, "x Axis", "ax.xaxis") - -# y Axis -circle(0, 0.44, "y Axis", "ax.yaxis") - -# Spine -circle(4.0, 0.7, "Spine", "ax.spines") - -# frame around figure... -fig.add_artist(Rectangle((0, 0), width=1, height=1, facecolor='none', - edgecolor='0.5', linewidth=10)) +circle(-0.3, 0.65) +text(-0.3, 0.45, "Figure") + +color = 'blue' +ax.annotate('Spines', xy=(4.0, 0.35), xytext=(3.3, 0.5), + weight='bold', color=color, + arrowprops=dict(arrowstyle='->', + connectionstyle="arc3", + color=color)) + +ax.annotate('', xy=(3.15, 0.0), xytext=(3.45, 0.45), + weight='bold', color=color, + arrowprops=dict(arrowstyle='->', + connectionstyle="arc3", + color=color)) + +ax.text(4.0, -0.4, "Made with https://matplotlib.org", + fontsize=10, ha="right", color='.5') plt.show() 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