Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bc1bfab

Browse filesBrowse files
committed
Make axisartist.clip_path pseudo-tests real.
The results seem to be acceptable.
1 parent f467768 commit bc1bfab
Copy full SHA for bc1bfab

File tree

Expand file treeCollapse file tree

3 files changed

+38
-26
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+38
-26
lines changed

‎lib/mpl_toolkits/axisartist/clip_path.py

Copy file name to clipboardExpand all lines: lib/mpl_toolkits/axisartist/clip_path.py
-26Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -133,29 +133,3 @@ def clip_line_to_rect(xline, yline, bbox):
133133
if bbox.containsx(x)]
134134

135135
return list(zip(lx4, ly4)), [c_left, c_bottom, c_right, c_top]
136-
137-
138-
if __name__ == "__main__":
139-
140-
import matplotlib.pyplot as plt
141-
142-
x = np.array([-3, -2, -1, 0., 1, 2, 3, 2, 1, 0, -1, -2, -3, 5])
143-
#x = np.array([-3, -2, -1, 0., 1, 2, 3])
144-
y = np.arange(len(x))
145-
#x0 = 2
146-
147-
plt.plot(x, y, lw=1)
148-
149-
from matplotlib.transforms import Bbox
150-
bb = Bbox.from_extents(-2, 3, 2, 12.5)
151-
lxy, ticks = clip_line_to_rect(x, y, bb)
152-
for xx, yy in lxy:
153-
plt.plot(xx, yy, lw=1, color="g")
154-
155-
ccc = iter(["ro", "go", "rx", "bx"])
156-
for ttt in ticks:
157-
cc = next(ccc)
158-
for (xx, yy), aa in ttt:
159-
plt.plot([xx], [yy], cc)
160-
161-
#xlim(
Loading
+38Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.