|
| 1 | +# ---------------------------------------------------------------------------- |
| 2 | +# Title: Scientific Visualisation - Python & Matplotlib |
| 3 | +# Author: Nicolas P. Rougier |
| 4 | +# License: BSD |
| 5 | +# ---------------------------------------------------------------------------- |
| 6 | +import numpy as np |
| 7 | +import matplotlib.pyplot as plt |
| 8 | +import matplotlib.patches as mpatches |
| 9 | +from matplotlib.collections import PatchCollection |
| 10 | + |
| 11 | + |
| 12 | +fig = plt.figure(figsize=(4.25, 4.25 * 95/115)) |
| 13 | +ax = fig.add_axes([0,0,1,1], frameon=False, aspect=1, |
| 14 | + xlim=(0-5,100+10), ylim=(-10,80+5), xticks=[], yticks=[]) |
| 15 | + |
| 16 | + |
| 17 | +box = mpatches.FancyBboxPatch( |
| 18 | + (0,0), 100, 83, mpatches.BoxStyle("Round", pad=0, rounding_size=2), |
| 19 | + linewidth=1., facecolor="0.9", edgecolor="black") |
| 20 | +ax.add_artist(box) |
| 21 | + |
| 22 | +box = mpatches.FancyBboxPatch( |
| 23 | + (0,0), 100, 75, mpatches.BoxStyle("Round", pad=0, rounding_size=0), |
| 24 | + linewidth=1., facecolor="white", edgecolor="black") |
| 25 | +ax.add_artist(box) |
| 26 | + |
| 27 | + |
| 28 | +box = mpatches.Rectangle( |
| 29 | + (5,5), 45, 30, zorder=10, |
| 30 | + linewidth=1.0, facecolor="white", edgecolor="black") |
| 31 | +ax.add_artist(box) |
| 32 | + |
| 33 | +box = mpatches.Rectangle( |
| 34 | + (5,40), 45, 30, zorder=10, |
| 35 | + linewidth=1.0, facecolor="white", edgecolor="black") |
| 36 | +ax.add_artist(box) |
| 37 | + |
| 38 | +box = mpatches.Rectangle( |
| 39 | + (55,5), 40, 65, zorder=10, |
| 40 | + linewidth=1.0, facecolor="white", edgecolor="black") |
| 41 | +ax.add_artist(box) |
| 42 | + |
| 43 | +# Window button |
| 44 | +X, Y = [5,10,15], [79,79,79] |
| 45 | +plt.scatter(X, Y, s=75, zorder=10, |
| 46 | + edgecolor="black", facecolor="white", linewidth=1) |
| 47 | + |
| 48 | + |
| 49 | +# Window size extension |
| 50 | +X, Y = [0, 0], [0, -8] |
| 51 | +plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False) |
| 52 | + |
| 53 | +X, Y = [100, 100], [0, -8] |
| 54 | +plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False) |
| 55 | + |
| 56 | +X, Y = [100, 108], [0, 0] |
| 57 | +plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False) |
| 58 | + |
| 59 | +X, Y = [100, 108], [75, 75] |
| 60 | +plt.plot(X, Y, color="black", linestyle=":", linewidth=1, clip_on=False) |
| 61 | + |
| 62 | + |
| 63 | +def ext_arrow(p0,p1,p2,p3): |
| 64 | + p0, p1 = np.asarray(p0), np.asarray(p1) |
| 65 | + p2, p3 = np.asarray(p2), np.asarray(p3) |
| 66 | + ax.arrow(*p0, *(p1-p0), zorder=20, linewidth=0, |
| 67 | + length_includes_head=True, width=.4, |
| 68 | + head_width=2, head_length=2, color="black") |
| 69 | + ax.arrow(*p3, *(p2-p3), zorder=20, linewidth=0, |
| 70 | + length_includes_head=True, width=.4, |
| 71 | + head_width=2, head_length=2, color="black") |
| 72 | + plt.plot([p1[0],p2[0]], [p1[1],p2[1]], linewidth=.9, color="black") |
| 73 | + |
| 74 | +def int_arrow(p0,p1): |
| 75 | + p0, p1 = np.asarray(p0), np.asarray(p1) |
| 76 | + ax.arrow(*((p0+p1)/2), *((p1-p0)/2), zorder=20, linewidth=0, |
| 77 | + length_includes_head=True, width=.4, |
| 78 | + head_width=2, head_length=2, color="black") |
| 79 | + ax.arrow(*((p0+p1)/2), *(-(p1-p0)/2), zorder=20, linewidth=0, |
| 80 | + length_includes_head=True, width=.4, |
| 81 | + head_width=2, head_length=2, color="black") |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | +x = 0 |
| 86 | +y = 10 |
| 87 | +ext_arrow( (x-4,y), (x,y), (x+5,y), (x+9,y) ) |
| 88 | +ax.text(x+9.5, y, "left", ha="left", va="center", size="x-small", zorder=20) |
| 89 | + |
| 90 | +x += 50 |
| 91 | +ext_arrow( (x-4,y), (x,y), (x+5,y), (x+9,y) ) |
| 92 | +ax.text(x-4.5, y, "wspace", ha="right", va="center", size="x-small", zorder=20) |
| 93 | + |
| 94 | +x += 45 |
| 95 | +ext_arrow( (x-4,y), (x,y), (x+5,y), (x+9,y) ) |
| 96 | +ax.text(x-4.5, y, "right", ha="right", va="center", size="x-small", zorder=20) |
| 97 | + |
| 98 | +y = 0 |
| 99 | +x = 25 |
| 100 | +ext_arrow( (x,y-4), (x,y), (x,y+5), (x,y+9) ) |
| 101 | +ax.text(x, y+9.5, "bottom", ha="center", va="bottom", size="x-small", zorder=20) |
| 102 | + |
| 103 | +y += 35 |
| 104 | +ext_arrow( (x,y-4), (x,y), (x,y+5), (x,y+9) ) |
| 105 | +ax.text(x, y-4.5, "hspace", ha="center", va="top", size="x-small", zorder=20) |
| 106 | + |
| 107 | +y += 35 |
| 108 | +ext_arrow( (x,y-4), (x,y), (x,y+5), (x,y+9) ) |
| 109 | +ax.text(x, y-4.5, "top", ha="center", va="top", size="x-small", zorder=20) |
| 110 | + |
| 111 | +int_arrow((0,-5), (100,-5)) |
| 112 | +ax.text(50, -5, "figure width", backgroundcolor="white", zorder=30, |
| 113 | + ha="center", va="center", size="x-small") |
| 114 | + |
| 115 | +int_arrow((105,0), (105,75)) |
| 116 | +ax.text(105, 75/2, "figure height", backgroundcolor="white", zorder=30, |
| 117 | + rotation = "vertical", ha="center", va="center", size="x-small") |
| 118 | + |
| 119 | +int_arrow((55,62.5), (95,62.5)) |
| 120 | +ax.text(75, 62.5, "axes width", backgroundcolor="white", zorder=30, |
| 121 | + ha="center", va="center", size="x-small") |
| 122 | + |
| 123 | +int_arrow((62.5,5), (62.5,70)) |
| 124 | +ax.text(62.5, 35, "axes height", backgroundcolor="white", zorder=30, |
| 125 | + rotation = "vertical", ha="center", va="center", size="x-small") |
| 126 | + |
| 127 | + |
| 128 | +plt.show() |
0 commit comments