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

Skip to content

Commit d6a83e5

Browse files
committed
Make axisartist.clip_path pseudo-tests real.
The results seem to be acceptable.
1 parent 3853805 commit d6a83e5

File tree

3 files changed

+38
-26
lines changed

3 files changed

+38
-26
lines changed

lib/mpl_toolkits/axisartist/clip_path.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -135,29 +135,3 @@ def clip_line_to_rect(xline, yline, bbox):
135135
if bbox.containsx(x)]
136136

137137
return list(zip(lx4, ly4)), [c_left, c_bottom, c_right, c_top]
138-
139-
140-
if __name__ == "__main__":
141-
142-
import matplotlib.pyplot as plt
143-
144-
x = np.array([-3, -2, -1, 0., 1, 2, 3, 2, 1, 0, -1, -2, -3, 5])
145-
#x = np.array([-3, -2, -1, 0., 1, 2, 3])
146-
y = np.arange(len(x))
147-
#x0 = 2
148-
149-
plt.plot(x, y, lw=1)
150-
151-
from matplotlib.transforms import Bbox
152-
bb = Bbox.from_extents(-2, 3, 2, 12.5)
153-
lxy, ticks = clip_line_to_rect(x, y, bb)
154-
for xx, yy in lxy:
155-
plt.plot(xx, yy, lw=1, color="g")
156-
157-
ccc = iter(["ro", "go", "rx", "bx"])
158-
for ttt in ticks:
159-
cc = six.next(ccc)
160-
for (xx, yy), aa in ttt:
161-
plt.plot([xx], [yy], cc)
162-
163-
#xlim(
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from __future__ import (absolute_import, division, print_function,
2+
unicode_literals)
3+
4+
import six
5+
6+
import numpy as np
7+
import matplotlib.pyplot as plt
8+
from matplotlib.testing.decorators import image_comparison
9+
from matplotlib.transforms import Bbox
10+
11+
from mpl_toolkits.axisartist.clip_path import clip_line_to_rect
12+
13+
14+
@image_comparison(baseline_images=['clip_path'],
15+
extensions=['png'], style='default')
16+
def test_clip_path():
17+
x = np.array([-3, -2, -1, 0., 1, 2, 3, 2, 1, 0, -1, -2, -3, 5])
18+
y = np.arange(len(x))
19+
20+
fig, ax = plt.subplots()
21+
ax.plot(x, y, lw=1)
22+
23+
bbox = Bbox.from_extents(-2, 3, 2, 12.5)
24+
rect = plt.Rectangle(bbox.p0, bbox.width, bbox.height,
25+
facecolor='none', edgecolor='k', ls='--')
26+
ax.add_patch(rect)
27+
28+
clipped_lines, ticks = clip_line_to_rect(x, y, bbox)
29+
for lx, ly in clipped_lines:
30+
ax.plot(lx, ly, lw=1, color='C1')
31+
for px, py in zip(lx, ly):
32+
assert bbox.contains(px, py)
33+
34+
ccc = iter(['C3o', 'C2x', 'C3o', 'C2x'])
35+
for ttt in ticks:
36+
cc = six.next(ccc)
37+
for (xx, yy), aa in ttt:
38+
ax.plot([xx], [yy], cc)

0 commit comments

Comments
 (0)