2
2
import unittest
3
3
<
EED3
/td>
4
4
from nose .tools import assert_equal
5
- import numpy .testing as np_test , assert_almost_equal
5
+ import numpy .testing as np_test
6
+ from numpy .testing import assert_almost_equal
6
7
from matplotlib .transforms import Affine2D , BlendedGenericTransform
7
8
from matplotlib .path import Path
8
9
from matplotlib .scale import LogScale
@@ -213,6 +214,11 @@ def setUp(self):
213
214
# self.stack1.write_graphviz(file('stack1.dot', 'w'))
214
215
# self.stack2.write_graphviz(file('stack2.dot', 'w'))
215
216
# self.stack2_subset.write_graphviz(file('stack2_subset.dot', 'w'))
217
+
218
+ def test_transform_depth (self ):
219
+ assert_equal (self .stack1 .depth , 4 )
220
+ assert_equal (self .stack2 .depth , 4 )
221
+ assert_equal (self .stack2_subset .depth , 3 )
216
222
217
223
def test_left_to_right_iteration (self ):
218
224
stack3 = (self .ta1 + (self .tn1 + (self .ta2 + self .tn2 ))) + self .ta3
@@ -224,7 +230,7 @@ def test_left_to_right_iteration(self):
224
230
self .tn2 + self .ta3 ,
225
231
self .ta3 ,
226
232
]
227
- r = [rh for lh , rh in stack3 ._iter_break_from_left_to_right ()]
233
+ r = [rh for _ , rh in stack3 ._iter_break_from_left_to_right ()]
228
234
self .assertEqual (len (r ), len (target_transforms ))
229
235
230
236
for target_stack , stack in zip (target_transforms , r ):
@@ -236,8 +242,11 @@ def test_transform_shortcuts(self):
236
242
237
243
# check that we cannot find a chain from the subset back to the superset
238
244
# (since the inverse of the Transform is not defined.)
239
- self .assertRaises (ValueError , self .stack2_subset .__sub__ , self .stack2 )
240
- self .assertRaises (ValueError , self .stack1 .__sub__ , self .stack2 )
245
+ with self .assertRaises (ValueError ):
246
+ self .stack2_subset - self .stack2
247
+
248
+ with self .assertRaises (ValueError ):
249
+ self .stack1 - self .stack2
241
250
242
251
aff1 = self .ta1 + (self .ta2 + self .ta3 )
243
252
aff2 = self .ta2 + self .ta3
@@ -312,6 +321,42 @@ def test_affine_simplification(self):
312
321
class TestTransformPlotInterface (unittest .TestCase ):
313
322
def<
F438
/span> tearDown (self ):
314
323
plt .close ()
324
+
325
+ def test_line_extent_axes_coords (self ):
326
+ # a simple line in axes coordinates
327
+ ax = plt .axes ()
328
+ ax .plot ([0.1 , 1.2 , 0.8 ], [0.9 , 0.5 , 0.8 ], transform = ax .transAxes )
329
+ np .testing .assert_array_equal (ax .dataLim .get_points (), np .array ([[0 , 0 ], [1 , 1 ]]))
330
+
331
+ def test_line_extent_data_coords (self ):
332
+ # a simple line in data coordinates
333
+ ax = plt .axes ()
334
+ ax .plot ([0.1 , 1.2 , 0.8 ], [0.9 , 0.5 , 0.8 ], transform = ax .transData )
335
+ np .testing .assert_array_equal (ax .dataLim .get_points (), np .array ([[ 0.1 , 0.5 ], [ 1.2 , 0.9 ]]))
336
+
337
+ def test_line_extent_compound_coords1 (self ):
338
+ # a simple line in data coordinates in the y component, and in axes coordinates in the x
339
+ ax = plt .axes ()
340
+ trans = mtrans .blended_transform_factory (ax .transAxes , ax .transData )
341
+ ax .plot ([0.1 , 1.2 , 0.8 ], [35 , - 5 , 18 ], transform = trans )
342
+ np .testing .assert_array_equal (ax .dataLim .get_points (), np .array ([[ 0. , - 5. ], [ 1. , 35. ]]))
343
+ plt .close ()
344
+
345
+ def test_line_extent_predata_transform_coords (self ):
346
+ # a simple line in (offset + data) coordinates
347
+ ax = plt .axes ()
348
+ trans = mtrans .Affine2D ().scale (10 ) + ax .transData
349
+ ax .plot ([0.1 , 1.2 , 0.8 ], [35 , - 5 , 18 ], transform = trans )
350
+ np .testing .assert_array_equal (ax .dataLim .get_points (), np .array ([[1. , - 50. ], [12. , 350. ]]))
351
+ plt .close ()
352
+
353
+ def test_line_extent_compound_coords2 (self ):
354
+ # a simple line in (offset + data) coordinates in the y component, and in axes coordinates in the x
355
+ ax = plt .axes ()
356
+ trans = mtrans .blended_transform_factory (ax .transAxes , mtrans .Affine2D ().scale (10 ) + ax .transData )
357
+ ax .plot ([0.1 , 1.2 , 0.8 ], [35 , - 5 , 18 ], transform = trans )
358
+ np .testing .assert_array_equal (ax .dataLim .get_points (), np .array ([[ 0. , - 50. ], [ 1. , 350. ]]))
359
+ plt .close ()
315
360
316
361
def test_line_extents_affine (self ):
317
362
ax = plt .axes ()
8162
@@ -362,10 +407,10 @@ def test_line_extents_for_non_affine_transData(self):
362
407
# before a transData transformation, hence the data limits
363
408
# are not what is being shown on the actual plot.
364
409
expeted_data_lim = np .array ([[0. , 0. ], [9. , 9. ]]) + [0 , 10 ]
365
- np .testing .assert_array_almost_equal (ax .dataLim .get_points (),
410
+ np .testing .assert_array_almost_equal (ax .dataLim .get_points (),
366
411
expeted_data_lim )
367
412
368
413
369
414
if __name__ == '__main__' :
370
415
import nose
371
- nose .runmodule (argv = ['-s' ,'--with-doctest' ], exit = False )
416
+ nose .runmodule (argv = ['-s' ,'--with-doctest' ], exit = False )
0 commit comments