8
8
from pandas import Series , DataFrame , MultiIndex , PeriodIndex , date_range
9
9
import pandas .util .testing as tm
10
10
from 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
12
12
13
13
import numpy as np
14
14
@@ -28,11 +28,6 @@ class TestSeriesPlots(unittest.TestCase):
28
28
29
29
@classmethod
30
30
def setUpClass (cls ):
31
- import sys
32
-
33
- # if 'IPython' in sys.modules:
34
- # raise nose.SkipTest
35
-
36
31
try :
37
32
import matplotlib as mpl
38
33
mpl .use ('Agg' , warn = False )
@@ -150,9 +145,16 @@ def test_irregular_datetime(self):
150
145
def test_hist (self ):
151
146
_check_plot_works (self .ts .hist )
152
147
_check_plot_works (self .ts .hist , grid = False )
153
-
148
+ _check_plot_works ( self . ts . hist , figsize = ( 8 , 10 ))
154
149
_check_plot_works (self .ts .hist , by = self .ts .index .month )
155
150
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
+
156
158
@slow
157
159
def test_kde (self ):
158
160
_skip_if_no_scipy ()
@@ -258,7 +260,8 @@ def test_plot(self):
258
260
(u'\u03b4 ' , 6 ),
259
261
(u'\u03b4 ' , 7 )], names = ['i0' , 'i1' ])
260
262
columns = MultiIndex .from_tuples ([('bar' , u'\u0394 ' ),
261
- ('bar' , u'\u0395 ' )], names = ['c0' , 'c1' ])
263
+ ('bar' , u'\u0395 ' )], names = ['c0' ,
264
+ 'c1' ])
262
265
df = DataFrame (np .random .randint (0 , 10 , (8 , 2 )),
263
266
columns = columns ,
264
267
index = index )
@@ -269,9 +272,9 @@ def test_nonnumeric_exclude(self):
269
272
import matplotlib .pyplot as plt
270
273
plt .close ('all' )
271
274
272
- df = DataFrame ({'A' : ["x" , "y" , "z" ], 'B' : [1 ,2 , 3 ]})
275
+ df = DataFrame ({'A' : ["x" , "y" , "z" ], 'B' : [1 , 2 , 3 ]})
273
276
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
275
278
276
279
@slow
277
280
def test_label (self ):
@@ -434,21 +437,24 @@ def test_bar_center(self):
434
437
ax = df .plot (kind = 'bar' , grid = True )
435
438
self .assertEqual (ax .xaxis .get_ticklocs ()[0 ],
436
439
ax .patches [0 ].get_x () + ax .patches [0 ].get_width ())
440
+
437
441
@slow
438
442
def test_bar_log (self ):
439
443
# GH3254, GH3298 matplotlib/matplotlib#1882, #1892
440
444
# regressions in 1.2.1
441
445
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 )
445
449
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 )
448
454
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 ()
452
458
453
459
@slow
454
460
def test_boxplot (self ):
@@ -508,6 +514,9 @@ def test_hist(self):
508
514
# make sure sharex, sharey is handled
509
515
_check_plot_works (df .hist , sharex = True , sharey = True )
510
516
517
+ # handle figsize arg
518
+ _check_plot_works (df .hist , figsize = (8 , 10 ))
519
+
511
520
# make sure xlabelsize and xrot are handled
512
521
ser = df [0 ]
513
522
xf , yf = 20 , 20
@@ -727,6 +736,7 @@ def test_invalid_kind(self):
727
736
df = DataFrame (np .random .randn (10 , 2 ))
728
737
self .assertRaises (ValueError , df .plot , kind = 'aasdf' )
729
738
739
+
730
740
class TestDataFrameGroupByPlots (unittest .TestCase ):
731
741
732
742
@classmethod
@@ -786,10 +796,10 @@ def test_time_series_plot_color_with_empty_kwargs(self):
786
796
787
797
plt .close ('all' )
788
798
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 ()
791
801
792
- line_colors = [ l .get_color () for l in ax .get_lines () ]
802
+ line_colors = [l .get_color () for l in ax .get_lines ()]
793
803
self .assert_ (line_colors == ['b' , 'g' , 'r' ])
794
804
795
805
@slow
@@ -829,7 +839,6 @@ def test_grouped_hist(self):
829
839
self .assertRaises (AttributeError , plotting .grouped_hist , df .A ,
830
840
by = df .C , foo = 'bar' )
831
841
832
-
833
842
def test_option_mpl_style (self ):
834
843
# just a sanity check
835
844
try :
@@ -845,14 +854,15 @@ def test_option_mpl_style(self):
845
854
except ValueError :
846
855
pass
847
856
857
+
848
858
def _check_plot_works (f , * args , ** kwargs ):
849
859
import matplotlib .pyplot as plt
850
860
851
861
fig = plt .gcf ()
852
862
plt .clf ()
853
863
ax = fig .add_subplot (211 )
854
864
ret = f (* args , ** kwargs )
855
- assert ( ret is not None ) # do something more intelligent
865
+ assert ret is not None # do something more intelligent
856
866
857
867
ax = fig .add_subplot (212 )
858
868
try :
@@ -865,10 +875,12 @@ def _check_plot_works(f, *args, **kwargs):
865
875
with ensure_clean () as path :
866
876
plt .savefig (path )
867
877
878
+
868
879
def curpath ():
869
880
pth , _ = os .path .split (os .path .abspath (__file__ ))
870
881
return pth
871
882
883
+
872
884
if __name__ == '__main__' :
873
885
nose .runmodule (argv = [__file__ , '-vvs' , '-x' , '--pdb' , '--pdb-failure' ],
874
886
exit = False )
0 commit comments