88from pandas import Series , DataFrame , MultiIndex , PeriodIndex , date_range
99import pandas .util .testing as tm
1010from pandas .util .testing import ensure_clean
11- from pandas .core .config import set_option , get_option , config_prefix
11+ from pandas .core .config import set_option
1212
1313import numpy as np
1414
@@ -28,11 +28,6 @@ class TestSeriesPlots(unittest.TestCase):
2828
2929 @classmethod
3030 def setUpClass (cls ):
31- import sys
32-
33- # if 'IPython' in sys.modules:
34- # raise nose.SkipTest
35-
3631 try :
3732 import matplotlib as mpl
3833 mpl .use ('Agg' , warn = False )
@@ -150,9 +145,16 @@ def test_irregular_datetime(self):
150145 def test_hist (self ):
151146 _check_plot_works (self .ts .hist )
152147 _check_plot_works (self .ts .hist , grid = False )
153-
148+ _check_plot_works ( self . ts . hist , figsize = ( 8 , 10 ))
154149 _check_plot_works (self .ts .hist , by = self .ts .index .month )
155150
151+ def test_plot_fails_when_ax_differs_from_figure (self ):
152+ from pylab import figure
153+ fig1 = figure ()
154+ fig2 = figure ()
155+ ax1 = fig1 .add_subplot (111 )
156+ self .assertRaises (AssertionError , self .ts .hist , ax = ax1 , figure = fig2 )
157+
156158 @slow
157159 def test_kde (self ):
158160 _skip_if_no_scipy ()
@@ -258,7 +260,8 @@ def test_plot(self):
258260 (u'\u03b4 ' , 6 ),
259261 (u'\u03b4 ' , 7 )], names = ['i0' , 'i1' ])
260262 columns = MultiIndex .from_tuples ([('bar' , u'\u0394 ' ),
261- ('bar' , u'\u0395 ' )], names = ['c0' , 'c1' ])
263+ ('bar' , u'\u0395 ' )], names = ['c0' ,
264+ 'c1' ])
262265 df = DataFrame (np .random .randint (0 , 10 , (8 , 2 )),
263266 columns = columns ,
264267 index = index )
@@ -269,9 +272,9 @@ def test_nonnumeric_exclude(self):
269272 import matplotlib .pyplot as plt
270273 plt .close ('all' )
271274
272- df = DataFrame ({'A' : ["x" , "y" , "z" ], 'B' : [1 ,2 , 3 ]})
275+ df = DataFrame ({'A' : ["x" , "y" , "z" ], 'B' : [1 , 2 , 3 ]})
273276 ax = df .plot ()
274- self .assert_ (len (ax .get_lines ()) == 1 ) # B was plotted
277+ self .assert_ (len (ax .get_lines ()) == 1 ) # B was plotted
275278
276279 @slow
277280 def test_label (self ):
@@ -434,21 +437,24 @@ def test_bar_center(self):
434437 ax = df .plot (kind = 'bar' , grid = True )
435438 self .assertEqual (ax .xaxis .get_ticklocs ()[0 ],
436439 ax .patches [0 ].get_x () + ax .patches [0 ].get_width ())
440+
437441 @slow
438442 def test_bar_log (self ):
439443 # GH3254, GH3298 matplotlib/matplotlib#1882, #1892
440444 # regressions in 1.2.1
441445
442- df = DataFrame ({'A' : [3 ] * 5 , 'B' : range (1 ,6 )}, index = range (5 ))
443- ax = df .plot (kind = 'bar' , grid = True ,log = True )
444- self .assertEqual (ax .yaxis .get_ticklocs ()[0 ],1.0 )
446+ df = DataFrame ({'A' : [3 ] * 5 , 'B' : range (1 , 6 )}, index = range (5 ))
447+ ax = df .plot (kind = 'bar' , grid = True , log = True )
448+ self .assertEqual (ax .yaxis .get_ticklocs ()[0 ], 1.0 )
445449
446- p1 = Series ([200 ,500 ]).plot (log = True ,kind = 'bar' )
447- p2 = DataFrame ([Series ([200 ,300 ]),Series ([300 ,500 ])]).plot (log = True ,kind = 'bar' ,subplots = True )
450+ p1 = Series ([200 , 500 ]).plot (log = True , kind = 'bar' )
451+ p2 = DataFrame ([Series ([200 , 300 ]),
452+ Series ([300 , 500 ])]).plot (log = True , kind = 'bar' ,
453+ subplots = True )
448454
449- (p1 .yaxis .get_ticklocs () == np .array ([ 0.625 , 1.625 ]))
450- (p2 [0 ].yaxis .get_ticklocs () == np .array ([ 1. , 10. , 100. , 1000. ])).all ()
451- (p2 [1 ].yaxis .get_ticklocs () == np .array ([ 1. , 10. , 100. , 1000. ])).all ()
455+ (p1 .yaxis .get_ticklocs () == np .array ([0.625 , 1.625 ]))
456+ (p2 [0 ].yaxis .get_ticklocs () == np .array ([1. , 10. , 100. , 1000. ])).all ()
457+ (p2 [1 ].yaxis .get_ticklocs () == np .array ([1. , 10. , 100. , 1000. ])).all ()
452458
453459 @slow
454460 def test_boxplot (self ):
@@ -508,6 +514,9 @@ def test_hist(self):
508514 # make sure sharex, sharey is handled
509515 _check_plot_works (df .hist , sharex = True , sharey = True )
510516
517+ # handle figsize arg
518+ _check_plot_works (df .hist , figsize = (8 , 10 ))
519+
511520 # make sure xlabelsize and xrot are handled
512521 ser = df [0 ]
513522 xf , yf = 20 , 20
@@ -727,6 +736,7 @@ def test_invalid_kind(self):
727736 df = DataFrame (np .random .randn (10 , 2 ))
728737 self .assertRaises (ValueError , df .plot , kind = 'aasdf' )
729738
739+
730740class TestDataFrameGroupByPlots (unittest .TestCase ):
731741
732742 @classmethod
@@ -786,10 +796,10 @@ def test_time_series_plot_color_with_empty_kwargs(self):
786796
787797 plt .close ('all' )
788798 for i in range (3 ):
789- ax = Series (np .arange (12 ) + 1 , index = date_range (
790- '1/1/2000' , periods = 12 )).plot ()
799+ ax = Series (np .arange (12 ) + 1 , index = date_range ('1/1/2000' ,
800+ periods = 12 )).plot ()
791801
792- line_colors = [ l .get_color () for l in ax .get_lines () ]
802+ line_colors = [l .get_color () for l in ax .get_lines ()]
793803 self .assert_ (line_colors == ['b' , 'g' , 'r' ])
794804
795805 @slow
@@ -829,7 +839,6 @@ def test_grouped_hist(self):
829839 self .assertRaises (AttributeError , plotting .grouped_hist , df .A ,
830840 by = df .C , foo = 'bar' )
831841
832-
833842 def test_option_mpl_style (self ):
834843 # just a sanity check
835844 try :
@@ -845,14 +854,15 @@ def test_option_mpl_style(self):
845854 except ValueError :
846855 pass
847856
857+
848858def _check_plot_works (f , * args , ** kwargs ):
849859 import matplotlib .pyplot as plt
850860
851861 fig = plt .gcf ()
852862 plt .clf ()
853863 ax = fig .add_subplot (211 )
854864 ret = f (* args , ** kwargs )
855- assert ( ret is not None ) # do something more intelligent
865+ assert ret is not None # do something more intelligent
856866
857867 ax = fig .add_subplot (212 )
858868 try :
@@ -865,10 +875,12 @@ def _check_plot_works(f, *args, **kwargs):
865875 with ensure_clean () as path :
866876 plt .savefig (path )
867877
878+
868879def curpath ():
869880 pth , _ = os .path .split (os .path .abspath (__file__ ))
870881 return pth
871882
883+
872884if __name__ == '__main__' :
873885 nose .runmodule (argv = [__file__ , '-vvs' , '-x' , '--pdb' , '--pdb-failure' ],
874886 exit = False )
0 commit comments