| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0722828 commit 05dbb33
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,20 +1,26 @@ | |||
| 1 | 1 | """ | |
| 2 | - ======================= | ||
| 3 | - Simple Anchored Artists | ||
| 4 | - ======================= | ||
| 5 | - | ||
| 2 | + ================ | ||
| 3 | + Anchored Artists | ||
| 4 | + ================ | ||
| 6 | 5 | """ | |
| 6 | + | ||
| 7 | 7 | import matplotlib.pyplot as plt | |
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | 10 | def draw_text(ax): | |
| 11 | + """ | ||
| 12 | + Draw two text-boxes, anchored by different corners to the upper-left | ||
| 13 | + side of the figure. | ||
| 14 | + """ | ||
| 11 | 15 | from matplotlib.offsetbox import AnchoredText | |
| 16 | + # loc=2 is equivalent to loc='upper left' | ||
| 12 | 17 | at = AnchoredText("Figure 1a", | |
| 13 | 18 | loc=2, prop=dict(size=8), frameon=True, | |
| 14 | 19 | ) | |
| 15 | 20 | at.patch.set_boxstyle("round,pad=0.,rounding_size=0.2") | |
| 16 | 21 | ax.add_artist(at) | |
| 17 | 22 | ||
| 23 | + # loc=3 is eqivalent to loc='lower left' | ||
| 18 | 24 | at2 = AnchoredText("Figure 1(b)", | |
| 19 | 25 | loc=3, prop=dict(size=8), frameon=True, | |
| 20 | 26 | bbox_to_anchor=(0., 1.), | |
@@ -24,7 +30,10 @@ def draw_text(ax): | |||
| 24 | 30 | ax.add_artist(at2) | |
| 25 | 31 | ||
| 26 | 32 | ||
| 27 | - def draw_circle(ax): # circle in the canvas coordinate | ||
| 33 | + def draw_circle(ax): | ||
| 34 | + """ | ||
| 35 | + Draw a circle in axis coordinates | ||
| 36 | + """ | ||
| 28 | 37 | from mpl_toolkits.axes_grid1.anchored_artists import AnchoredDrawingArea | |
| 29 | 38 | from matplotlib.patches import Circle | |
| 30 | 39 | ada = AnchoredDrawingArea(20, 20, 0, 0, | |
@@ -35,18 +44,22 @@ def draw_circle(ax): # circle in the canvas coordinate | |||
| 35 | 44 | ||
| 36 | 45 | ||
| 37 | 46 | def draw_ellipse(ax): | |
| 47 | + """ | ||
| 48 | + Draw an ellipse of width=0.1, height=0.15 in data coordinates | ||
| 49 | + """ | ||
| 38 | 50 | from mpl_toolkits.axes_grid1.anchored_artists import AnchoredEllipse | |
| 39 | - # draw an ellipse of width=0.1, height=0.15 in the data coordinate | ||
| 40 | 51 | ae = AnchoredEllipse(ax.transData, width=0.1, height=0.15, angle=0., | |
| 41 | 52 | loc=3, pad=0.5, borderpad=0.4, frameon=True) | |
| 42 | 53 | ||
| 43 | 54 | ax.add_artist(ae) | |
| 44 | 55 | ||
| 45 | 56 | ||
| 46 | 57 | def draw_sizebar(ax): | |
| 58 | + """ | ||
| 59 | + Draw a horizontal bar with length of 0.1 in data coordinates, | ||
| 60 | + with a fixed label underneath. | ||
| 61 | + """ | ||
| 47 | 62 | from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar | |
| 48 | - # draw a horizontal bar with length of 0.1 in Data coordinate | ||
| 49 | - # (ax.transData) with a label underneath. | ||
| 50 | 63 | asb = AnchoredSizeBar(ax.transData, | |
| 51 | 64 | 0.1, | |
| 52 | 65 | r"1$^{\prime}$", | |
@@ -56,13 +69,12 @@ def draw_sizebar(ax): | |||
| 56 | 69 | ax.add_artist(asb) | |
| 57 | 70 | ||
| 58 | 71 | ||
| 59 | - if 1: | ||
| 60 | - ax = plt.gca() | ||
| 61 | - ax.set_aspect(1.) | ||
| 72 | + ax = plt.gca() | ||
| 73 | + ax.set_aspect(1.) | ||
| 62 | 74 | ||
| 63 | - draw_text(ax) | ||
| 64 | - draw_circle(ax) | ||
| 65 | - draw_ellipse(ax) | ||
| 66 | - draw_sizebar(ax) | ||
| 75 | + draw_text(ax) | ||
| 76 | + draw_circle(ax) | ||
| 77 | + draw_ellipse(ax) | ||
| 78 | + draw_sizebar(ax) | ||
| 67 | 79 | ||
| 68 | - plt.show() | ||
| 80 | + plt.show() | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments