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

Skip to content

Commit c162b88

Browse files
daniel-s-ingramQuLogic
authored andcommitted
Separate test from AngleMarker class
1 parent 27bd23b commit c162b88

File tree

3 files changed

+54
-120
lines changed

3 files changed

+54
-120
lines changed

examples/lines_bars_and_markers/AngleArc.py

Lines changed: 0 additions & 68 deletions
This file was deleted.

examples/lines_bars_and_markers/AngleMarker.py

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -124,55 +124,10 @@ def set_text_pos(self, xy):
124124
_text_pos = property(get_text_pos, set_text_pos)
125125

126126

127-
fig, ax = plt.subplots()
128-
129-
ax.plot([2, .5, -1], [1, .2, 1])
130-
am = AngleMarker((.5, .2), (2, 1), (-1, 1), size=50, units="pixels", ax=ax,
131-
text=r"$\theta$")
132-
plt.show()
133-
134-
135-
def testing(size=0.25, units="axes fraction", dpi=100, fs=(6.4, 5),
136-
show=False):
137-
138-
fig, axes = plt.subplots(2, 2, sharex="col", sharey="row", dpi=dpi,
139-
figsize=fs,
140-
gridspec_kw=dict(width_ratios=[1, 3],
141-
height_ratios=[3, 1]))
142-
143-
def plot_angle(ax, pos, vec1, vec2, acol="C0", **kwargs):
144-
ax.plot([vec1[0], pos[0], vec2[0]], [vec1[1], pos[1], vec2[1]],
145-
color=acol)
146-
am = AngleMarker(pos, vec1, vec2, ax=ax, text=r"$\theta$", **kwargs)
147-
148-
tx = "figsize={}, dpi={}, arcsize={} {}".format(fs, dpi, size, units)
149-
axes[0, 1].set_title(tx, loc="right", size=9)
150-
kw = dict(size=size, units=units)
151-
p = (.5, .2), (2, 0), (1, 1)
152-
plot_angle(axes[0, 0], *p, **kw)
153-
plot_angle(axes[0, 1], *p, **kw)
154-
plot_angle(axes[1, 1], *p, **kw)
155-
kw.update(acol="limegreen")
156-
plot_angle(axes[0, 0], (1.2, 0), (1, -1), (1.3, -.8), **kw)
157-
plot_angle(axes[1, 1], (0.2, 1), (0, 0), (.3, .2), **kw)
158-
plot_angle(axes[0, 1], (0.2, 0), (0, -1), (.3, -.8), **kw)
159-
kw.update(acol="crimson")
160-
plot_angle(axes[1, 0], (1, .5), (1, 1), (2, .5), **kw)
161-
162-
fig.tight_layout()
163-
fig.savefig(tx.replace("=", "_") + ".png")
164-
fig.savefig(tx.replace("=", "_") + ".pdf")
165-
if show:
166-
plt.show()
167-
168-
169-
s = [(0.25, "axes min"), (0.25, "axes max"),
170-
(0.25, "axes width"), (0.25, "axes height"),
171-
(100, "pixels"), (72, "points")]
172-
d = [72, 144]
173-
f = [(6.4, 5), (12.8, 10)]
174-
175-
import itertools
176-
177-
for (size, unit), dpi, fs in itertools.product(s, d, f):
178-
testing(size=size, units=unit, dpi=dpi, fs=fs)
127+
if __name__ == "__main__":
128+
fig, ax = plt.subplots()
129+
130+
ax.plot([2, .5, -1], [1, .2, 1])
131+
am = AngleMarker((.5, .2), (2, 1), (-1, 1), size=50, units="pixels", ax=ax,
132+
text=r"$\theta$")
133+
plt.show()
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import itertools
2+
import matplotlib.pyplot as plt
3+
from AngleMarker import AngleMarker
4+
5+
6+
def testing(size=0.25, units="axes fraction", dpi=100, fs=(6.4, 5),
7+
show=False):
8+
9+
fig, axes = plt.subplots(2, 2, sharex="col", sharey="row", dpi=dpi,
10+
figsize=fs,
11+
gridspec_kw=dict(width_ratios=[1, 3],
12+
height_ratios=[3, 1]))
13+
14+
def plot_angle(ax, pos, vec1, vec2, acol="C0", **kwargs):
15+
ax.plot([vec1[0], pos[0], vec2[0]], [vec1[1], pos[1], vec2[1]],
16+
color=acol)
17+
am = AngleMarker(pos, vec1, vec2, ax=ax, text=r"$\theta$", **kwargs)
18+
19+
tx = "figsize={}, dpi={}, arcsize={} {}".format(fs, dpi, size, units)
20+
axes[0, 1].set_title(tx, loc="right", size=9)
21+
kw = dict(size=size, units=units)
22+
p = (.5, .2), (2, 0), (1, 1)
23+
plot_angle(axes[0, 0], *p, **kw)
24+
plot_angle(axes[0, 1], *p, **kw)
25+
plot_angle(axes[1, 1], *p, **kw)
26+
kw.update(acol="limegreen")
27+
plot_angle(axes[0, 0], (1.2, 0), (1, -1), (1.3, -.8), **kw)
28+
plot_angle(axes[1, 1], (0.2, 1), (0, 0), (.3, .2), **kw)
29+
plot_angle(axes[0, 1], (0.2, 0), (0, -1), (.3, -.8), **kw)
30+
kw.update(acol="crimson")
31+
plot_angle(axes[1, 0], (1, .5), (1, 1), (2, .5), **kw)
32+
33+
fig.tight_layout()
34+
fig.savefig(tx.replace("=", "_") + ".png")
35+
fig.savefig(tx.replace("=", "_") + ".pdf")
36+
if show:
37+
plt.show()
38+
39+
40+
s = [(0.25, "axes min"), (0.25, "axes max"),
41+
(0.25, "axes width"), (0.25, "axes height"),
42+
(100, "pixels"), (72, "points")]
43+
d = [72, 144]
44+
f = [(6.4, 5), (12.8, 10)]
45+
46+
for (size, unit), dpi, fs in itertools.product(s, d, f):
47+
testing(size=size, units=unit, dpi=dpi, fs=fs)

0 commit comments

Comments
 (0)