22import unittest
33
44from 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
67from matplotlib .transforms import Affine2D , BlendedGenericTransform
78from matplotlib .path import Path
89from matplotlib .scale import LogScale
@@ -213,6 +214,11 @@ def setUp(self):
213214# self.stack1.write_graphviz(file('stack1.dot', 'w'))
214215# self.stack2.write_graphviz(file('stack2.dot', 'w'))
215216# 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 )
216222
217223 def test_left_to_right_iteration (self ):
218224 stack3 = (self .ta1 + (self .tn1 + (self .ta2 + self .tn2 ))) + self .ta3
@@ -224,7 +230,7 @@ def test_left_to_right_iteration(self):
224230 self .tn2 + self .ta3 ,
225231 self .ta3 ,
226232 ]
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 ()]
228234 self .assertEqual (len (r ), len (target_transforms ))
229235
230236 for target_stack , stack in zip (target_transforms , r ):
@@ -236,8 +242,11 @@ def test_transform_shortcuts(self):
236242
237243 # check that we cannot find a chain from the subset back to the superset
238244 # (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
241250
242251 aff1 = self .ta1 + (self .ta2 + self .ta3 )
243252 aff2 = self .ta2 + self .ta3
@@ -312,6 +321,42 @@ def test_affine_simplification(self):
312321class TestTransformPlotInterface (unittest .TestCase ):
313322 def tearDown (self ):
314323 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 ()
315360
316361 def test_line_extents_affine (self ):
317362 ax = plt .axes ()
@@ -362,10 +407,10 @@ def test_line_extents_for_non_affine_transData(self):
362407 # before a transData transformation, hence the data limits
363408 # are not what is being shown on the actual plot.
364409 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 (),
366411 expeted_data_lim )
367412
368413
369414if __name__ == '__main__' :
370415 import nose
371- nose .runmodule (argv = ['-s' ,'--with-doctest' ], exit = False )
416+ nose .runmodule (argv = ['-s' ,'--with-doctest' ], exit = False )
0 commit comments