6
6
from datetime import datetime , date
7
7
8
8
from pandas import Series , DataFrame , MultiIndex , PeriodIndex , date_range
9
- from pandas .compat import range , lrange , StringIO , lmap , lzip , u , map , zip
9
+ from pandas .compat import range , lrange , StringIO , lmap , lzip , u , zip
10
10
import pandas .util .testing as tm
11
11
from pandas .util .testing import ensure_clean
12
12
from pandas .core .config import set_option
13
13
14
14
15
15
import numpy as np
16
16
from numpy import random
17
+ from numpy .random import randn
17
18
18
19
from numpy .testing import assert_array_equal
19
20
from numpy .testing .decorators import slow
@@ -64,7 +65,7 @@ def test_plot(self):
64
65
_check_plot_works (self .series [:5 ].plot , kind = 'barh' )
65
66
_check_plot_works (self .series [:10 ].plot , kind = 'barh' )
66
67
67
- Series (np . random . randn (10 )).plot (kind = 'bar' , color = 'black' )
68
+ Series (randn (10 )).plot (kind = 'bar' , color = 'black' )
68
69
69
70
# figsize and title
70
71
import matplotlib .pyplot as plt
@@ -84,7 +85,7 @@ def test_bar_colors(self):
84
85
custom_colors = 'rgcby'
85
86
86
87
plt .close ('all' )
87
- df = DataFrame (np . random . randn (5 , 5 ))
88
+ df = DataFrame (randn (5 , 5 ))
88
89
ax = df .plot (kind = 'bar' )
89
90
90
91
rects = ax .patches
@@ -141,7 +142,7 @@ def test_bar_colors(self):
141
142
142
143
@slow
143
144
def test_bar_linewidth (self ):
144
- df = DataFrame (np . random . randn (5 , 5 ))
145
+ df = DataFrame (randn (5 , 5 ))
145
146
146
147
# regular
147
148
ax = df .plot (kind = 'bar' , linewidth = 2 )
@@ -160,15 +161,15 @@ def test_bar_linewidth(self):
160
161
self .assert_ (r .get_linewidth () == 2 )
161
162
162
163
def test_rotation (self ):
163
- df = DataFrame (np . random . randn (5 , 5 ))
164
+ df = DataFrame (randn (5 , 5 ))
164
165
ax = df .plot (rot = 30 )
165
166
for l in ax .get_xticklabels ():
166
167
self .assert_ (l .get_rotation () == 30 )
167
168
168
169
def test_irregular_datetime (self ):
169
170
rng = date_range ('1/1/2000' , '3/1/2000' )
170
171
rng = rng [[0 , 1 , 2 , 3 , 5 , 9 , 10 , 11 , 12 ]]
171
- ser = Series (np . random . randn (len (rng )), rng )
172
+ ser = Series (randn (len (rng )), rng )
172
173
ax = ser .plot ()
173
174
xp = datetime (1999 , 1 , 1 ).toordinal ()
174
175
ax .set_xlim ('1/1/1999' , '1/1/2001' )
@@ -224,6 +225,25 @@ def test_hist_layout_with_by(self):
224
225
_check_plot_works (df .weight .hist , by = df .category , layout = (4 , 1 ))
225
226
plt .close ('all' )
226
227
228
+ @slow
229
+ def test_hist_no_overlap (self ):
230
+ from matplotlib .pyplot import subplot , gcf , close
231
+ x = Series (randn (2 ))
232
+ y = Series (randn (2 ))
233
+ subplot (121 )
234
+ x .hist ()
235
+ subplot (122 )
236
+ y .hist ()
237
+ fig = gcf ()
238
+ axes = fig .get_axes ()
239
+ self .assertEqual (len (axes ), 2 )
240
+ close ('all' )
241
+
242
+ @slow
243
+ def test_plot_fails_with_dupe_color_and_style (self ):
244
+ x = Series (randn (2 ))
245
+ self .assertRaises (ValueError , x .plot , style = 'k--' , color = 'k' )
246
+
227
247
def test_plot_fails_when_ax_differs_from_figure (self ):
228
248
from pylab import figure
229
249
fig1 = figure ()
@@ -362,7 +382,7 @@ def test_nonnumeric_exclude(self):
362
382
def test_label (self ):
363
383
import matplotlib .pyplot as plt
364
384
plt .close ('all' )
365
- df = DataFrame (np . random . randn (10 , 3 ), columns = ['a' , 'b' , 'c' ])
385
+ df = DataFrame (randn (10 , 3 ), columns = ['a' , 'b' , 'c' ])
366
386
ax = df .plot (x = 'a' , y = 'b' )
367
387
self .assert_ (ax .xaxis .get_label ().get_text () == 'a' )
368
388
@@ -487,7 +507,7 @@ def test_subplots(self):
487
507
488
508
@slow
489
509
def test_plot_bar (self ):
490
- df = DataFrame (np . random . randn (6 , 4 ),
510
+ df = DataFrame (randn (6 , 4 ),
491
511
index = list (string .ascii_letters [:6 ]),
492
512
columns = ['one' , 'two' , 'three' , 'four' ])
493
513
@@ -496,7 +516,7 @@ def test_plot_bar(self):
496
516
_check_plot_works (df .plot , kind = 'bar' , subplots = True )
497
517
_check_plot_works (df .plot , kind = 'bar' , stacked = True )
498
518
499
- df = DataFrame (np . random . randn (10 , 15 ),
519
+ df = DataFrame (randn (10 , 15 ),
500
520
index = list (string .ascii_letters [:10 ]),
501
521
columns = lrange (15 ))
502
522
_check_plot_works (df .plot , kind = 'bar' )
@@ -537,7 +557,7 @@ def test_bar_log(self):
537
557
538
558
@slow
539
559
def test_boxplot (self ):
540
- df = DataFrame (np . random . randn (6 , 4 ),
560
+ df = DataFrame (randn (6 , 4 ),
541
561
index = list (string .ascii_letters [:6 ]),
542
562
columns = ['one' , 'two' , 'three' , 'four' ])
543
563
df ['indic' ] = ['foo' , 'bar' ] * 3
@@ -563,7 +583,7 @@ def test_boxplot(self):
563
583
@slow
564
584
def test_kde (self ):
565
585
_skip_if_no_scipy ()
566
- df = DataFrame (np . random . randn (100 , 4 ))
586
+ df = DataFrame (randn (100 , 4 ))
567
587
_check_plot_works (df .plot , kind = 'kde' )
568
588
_check_plot_works (df .plot , kind = 'kde' , subplots = True )
569
589
ax = df .plot (kind = 'kde' )
@@ -575,21 +595,21 @@ def test_kde(self):
575
595
@slow
576
596
def test_hist (self ):
577
597
import matplotlib .pyplot as plt
578
- df = DataFrame (np . random . randn (100 , 4 ))
598
+ df = DataFrame (randn (100 , 4 ))
579
599
_check_plot_works (df .hist )
580
600
_check_plot_works (df .hist , grid = False )
581
601
582
602
# make sure layout is handled
583
- df = DataFrame (np . random . randn (100 , 3 ))
603
+ df = DataFrame (randn (100 , 3 ))
584
604
_check_plot_works (df .hist )
585
605
axes = df .hist (grid = False )
586
606
self .assert_ (not axes [1 , 1 ].get_visible ())
587
607
588
- df = DataFrame (np . random . randn (100 , 1 ))
608
+ df = DataFrame (randn (100 , 1 ))
589
609
_check_plot_works (df .hist )
590
610
591
611
# make sure layout is handled
592
- df = DataFrame (np . random . randn (100 , 6 ))
612
+ df = DataFrame (randn (100 , 6 ))
593
613
_check_plot_works (df .hist )
594
614
595
615
# make sure sharex, sharey is handled
@@ -641,7 +661,7 @@ def test_hist(self):
641
661
def test_hist_layout (self ):
642
662
import matplotlib .pyplot as plt
643
663
plt .close ('all' )
644
- df = DataFrame (np . random . randn (100 , 4 ))
664
+ df = DataFrame (randn (100 , 4 ))
645
665
646
666
layout_to_expected_size = (
647
667
{'layout' : None , 'expected_size' : (2 , 2 )}, # default is 2x2
@@ -666,8 +686,7 @@ def test_hist_layout(self):
666
686
def test_scatter (self ):
667
687
_skip_if_no_scipy ()
668
688
669
- df = DataFrame (np .random .randn (100 , 4 ))
670
- df = DataFrame (np .random .randn (100 , 2 ))
689
+ df = DataFrame (randn (100 , 2 ))
671
690
import pandas .tools .plotting as plt
672
691
673
692
def scat (** kwds ):
@@ -730,11 +749,11 @@ def test_radviz(self):
730
749
731
750
@slow
732
751
def test_plot_int_columns (self ):
733
- df = DataFrame (np . random . randn (100 , 4 )).cumsum ()
752
+ df = DataFrame (randn (100 , 4 )).cumsum ()
734
753
_check_plot_works (df .plot , legend = True )
735
754
736
755
def test_legend_name (self ):
737
- multi = DataFrame (np . random . randn (4 , 4 ),
756
+ multi = DataFrame (randn (4 , 4 ),
738
757
columns = [np .array (['a' , 'a' , 'b' , 'b' ]),
739
758
np .array (['x' , 'y' , 'x' , 'y' ])])
740
759
multi .columns .names = ['group' , 'individual' ]
@@ -751,7 +770,7 @@ def test_style_by_column(self):
751
770
import matplotlib .pyplot as plt
752
771
fig = plt .gcf ()
753
772
754
- df = DataFrame (np . random . randn (100 , 3 ))
773
+ df = DataFrame (randn (100 , 3 ))
755
774
for markers in [{0 : '^' , 1 : '+' , 2 : 'o' },
756
775
{0 : '^' , 1 : '+' },
757
776
['^' , '+' , 'o' ],
@@ -771,7 +790,7 @@ def test_line_colors(self):
771
790
custom_colors = 'rgcby'
772
791
773
792
plt .close ('all' )
774
- df = DataFrame (np . random . randn (5 , 5 ))
793
+ df = DataFrame (randn (5 , 5 ))
775
794
776
795
ax = df .plot (color = custom_colors )
777
796
@@ -826,7 +845,7 @@ def test_default_color_cycle(self):
826
845
plt .rcParams ['axes.color_cycle' ] = list ('rgbk' )
827
846
828
847
plt .close ('all' )
829
- df = DataFrame (np . random . randn (5 , 3 ))
848
+ df = DataFrame (randn (5 , 3 ))
830
849
ax = df .plot ()
831
850
832
851
lines = ax .get_lines ()
@@ -856,13 +875,13 @@ def test_all_invalid_plot_data(self):
856
875
@slow
857
876
def test_partially_invalid_plot_data (self ):
858
877
kinds = 'line' , 'bar' , 'barh' , 'kde' , 'density'
859
- df = DataFrame (np . random . randn (10 , 2 ), dtype = object )
878
+ df = DataFrame (randn (10 , 2 ), dtype = object )
860
879
df [np .random .rand (df .shape [0 ]) > 0.5 ] = 'a'
861
880
for kind in kinds :
862
881
self .assertRaises (TypeError , df .plot , kind = kind )
863
882
864
883
def test_invalid_kind (self ):
865
- df = DataFrame (np . random . randn (10 , 2 ))
884
+ df = DataFrame (randn (10 , 2 ))
866
885
self .assertRaises (ValueError , df .plot , kind = 'aasdf' )
867
886
868
887
@@ -919,7 +938,7 @@ def test_time_series_plot_color_kwargs(self):
919
938
def test_time_series_plot_color_with_empty_kwargs (self ):
920
939
import matplotlib as mpl
921
940
import matplotlib .pyplot as plt
922
-
941
+
923
942
def_colors = mpl .rcParams ['axes.color_cycle' ]
924
943
925
944
plt .close ('all' )
@@ -933,7 +952,7 @@ def test_time_series_plot_color_with_empty_kwargs(self):
933
952
@slow
934
953
def test_grouped_hist (self ):
935
954
import matplotlib .pyplot as plt
936
- df = DataFrame (np . random . randn (500 , 2 ), columns = ['A' , 'B' ])
955
+ df = DataFrame (randn (500 , 2 ), columns = ['A' , 'B' ])
937
956
df ['C' ] = np .random .randint (0 , 4 , 500 )
938
957
axes = plotting .grouped_hist (df .A , by = df .C )
939
958
self .assert_ (len (axes .ravel ()) == 4 )
@@ -1036,7 +1055,7 @@ def test_option_mpl_style(self):
1036
1055
pass
1037
1056
1038
1057
def test_invalid_colormap (self ):
1039
- df = DataFrame (np . random . randn (3 , 2 ), columns = ['A' , 'B' ])
1058
+ df = DataFrame (randn (3 , 2 ), columns = ['A' , 'B' ])
1040
1059
self .assertRaises (ValueError , df .plot , colormap = 'invalid_colormap' )
1041
1060
1042
1061
0 commit comments