@@ -117,12 +117,21 @@ def test_scatter_matrix_axis(self, pass_axis):
117
117
ax = ax ,
118
118
)
119
119
axes0_labels = axes [0 ][0 ].yaxis .get_majorticklabels ()
120
-
121
120
# GH 5662
122
121
expected = ["-2" , "0" , "2" ]
123
122
_check_text_labels (axes0_labels , expected )
124
123
_check_ticks_props (axes , xlabelsize = 8 , xrot = 90 , ylabelsize = 8 , yrot = 0 )
125
124
125
+ @td .skip_if_no_scipy
126
+ @pytest .mark .parametrize ("pass_axis" , [False , True ])
127
+ def test_scatter_matrix_axis_smaller (self , pass_axis ):
128
+ scatter_matrix = plotting .scatter_matrix
129
+
130
+ ax = None
131
+ if pass_axis :
132
+ _ , ax = mpl .pyplot .subplots (3 , 3 )
133
+
134
+ df = DataFrame (np .random .RandomState (42 ).randn (100 , 3 ))
126
135
df [0 ] = (df [0 ] - 2 ) / 3
127
136
128
137
# we are plotting multiples on a sub-plot
@@ -299,38 +308,47 @@ def test_parallel_coordinates_with_sorted_labels(self):
299
308
# labels and colors are ordered strictly increasing
300
309
assert prev [1 ] < nxt [1 ] and prev [0 ] < nxt [0 ]
301
310
302
- def test_radviz (self , iris ):
303
- from matplotlib import cm
304
-
311
+ def test_radviz_no_warning (self , iris ):
305
312
from pandas .plotting import radviz
306
313
307
314
df = iris
308
315
# Ensure no UserWarning when making plot
309
316
with tm .assert_produces_warning (None ):
310
317
_check_plot_works (radviz , frame = df , class_column = "Name" )
311
318
312
- rgba = ("#556270" , "#4ECDC4" , "#C7F464" )
313
- ax = _check_plot_works (radviz , frame = df , class_column = "Name" , color = rgba )
319
+ @pytest .mark .parametrize (
320
+ "color" ,
321
+ [("#556270" , "#4ECDC4" , "#C7F464" ), ["dodgerblue" , "aquamarine" , "seagreen" ]],
322
+ )
323
+ def test_radviz_color (self , iris , color ):
324
+ from pandas .plotting import radviz
325
+
326
+ df = iris
327
+ ax = _check_plot_works (radviz , frame = df , class_column = "Name" , color = color )
314
328
# skip Circle drawn as ticks
315
329
patches = [p for p in ax .patches [:20 ] if p .get_label () != "" ]
316
- _check_colors (patches [:10 ], facecolors = rgba , mapping = df ["Name" ][:10 ])
330
+ _check_colors (patches [:10 ], facecolors = color , mapping = df ["Name" ][:10 ])
317
331
318
- cnames = [ "dodgerblue" , "aquamarine" , "seagreen" ]
319
- _check_plot_works ( radviz , frame = df , class_column = "Name" , color = cnames )
320
- patches = [ p for p in ax . patches [: 20 ] if p . get_label () != "" ]
321
- _check_colors ( patches , facecolors = cnames , mapping = df [ "Name" ][: 10 ])
332
+ def test_radviz_color_cmap ( self , iris ):
333
+ from matplotlib import cm
334
+
335
+ from pandas . plotting import radviz
322
336
323
- _check_plot_works (radviz , frame = df , class_column = "Name" , colormap = cm .jet )
337
+ df = iris
338
+ ax = _check_plot_works (radviz , frame = df , class_column = "Name" , colormap = cm .jet )
324
339
cmaps = [cm .jet (n ) for n in np .linspace (0 , 1 , df ["Name" ].nunique ())]
325
340
patches = [p for p in ax .patches [:20 ] if p .get_label () != "" ]
326
341
_check_colors (patches , facecolors = cmaps , mapping = df ["Name" ][:10 ])
327
342
343
+ def test_radviz_colors_handles (self ):
344
+ from pandas .plotting import radviz
345
+
328
346
colors = [[0.0 , 0.0 , 1.0 , 1.0 ], [0.0 , 0.5 , 1.0 , 1.0 ], [1.0 , 0.0 , 0.0 , 1.0 ]]
329
347
df = DataFrame (
330
348
{"A" : [1 , 2 , 3 ], "B" : [2 , 1 , 3 ], "C" : [3 , 2 , 1 ], "Name" : ["b" , "g" , "r" ]}
331
349
)
332
350
ax = radviz (df , "Name" , color = colors )
333
- handles , labels = ax .get_legend_handles_labels ()
351
+ handles , _ = ax .get_legend_handles_labels ()
334
352
_check_colors (handles , facecolors = colors )
335
353
336
354
def test_subplot_titles (self , iris ):
@@ -342,6 +360,10 @@ def test_subplot_titles(self, iris):
342
360
plot = df .plot (subplots = True , title = title )
343
361
assert [p .get_title () for p in plot ] == title
344
362
363
+ def test_subplot_titles_too_much (self , iris ):
364
+ df = iris .drop ("Name" , axis = 1 ).head ()
365
+ # Use the column names as the subplot titles
366
+ title = list (df .columns )
345
367
# Case len(title) > len(df)
346
368
msg = (
347
369
"The length of `title` must equal the number of columns if "
@@ -350,10 +372,22 @@ def test_subplot_titles(self, iris):
350
372
with pytest .raises (ValueError , match = msg ):
351
373
df .plot (subplots = True , title = title + ["kittens > puppies" ])
352
374
375
+ def test_subplot_titles_too_little (self , iris ):
376
+ df = iris .drop ("Name" , axis = 1 ).head ()
377
+ # Use the column names as the subplot titles
378
+ title = list (df .columns )
379
+ msg = (
380
+ "The length of `title` must equal the number of columns if "
381
+ "using `title` of type `list` and `subplots=True`"
382
+ )
353
383
# Case len(title) < len(df)
354
384
with pytest .raises (ValueError , match = msg ):
355
385
df .plot (subplots = True , title = title [:2 ])
356
386
387
+ def test_subplot_titles_subplots_false (self , iris ):
388
+ df = iris .drop ("Name" , axis = 1 ).head ()
389
+ # Use the column names as the subplot titles
390
+ title = list (df .columns )
357
391
# Case subplots=False and title is of type list
358
392
msg = (
359
393
"Using `title` of type `list` is not supported unless "
@@ -362,6 +396,10 @@ def test_subplot_titles(self, iris):
362
396
with pytest .raises (ValueError , match = msg ):
363
397
df .plot (subplots = False , title = title )
364
398
399
+ def test_subplot_titles_numeric_square_layout (self , iris ):
400
+ df = iris .drop ("Name" , axis = 1 ).head ()
401
+ # Use the column names as the subplot titles
402
+ title = list (df .columns )
365
403
# Case df with 3 numeric columns but layout of (2,2)
366
404
plot = df .drop ("SepalWidth" , axis = 1 ).plot (
367
405
subplots = True , layout = (2 , 2 ), title = title [:- 1 ]
@@ -380,6 +418,8 @@ def test_get_standard_colors_random_seed(self):
380
418
rand2 = np .random .random ()
381
419
assert rand1 != rand2
382
420
421
+ def test_get_standard_colors_consistency (self ):
422
+ # GH17525
383
423
# Make sure it produces the same colors every time it's called
384
424
from pandas .plotting ._matplotlib .style import get_standard_colors
385
425
@@ -433,7 +473,8 @@ def test_get_standard_colors_no_appending(self):
433
473
p = df .A .plot .bar (figsize = (16 , 7 ), color = color_list )
434
474
assert p .patches [1 ].get_facecolor () == p .patches [17 ].get_facecolor ()
435
475
436
- def test_dictionary_color (self ):
476
+ @pytest .mark .parametrize ("kind" , ["bar" , "line" ])
477
+ def test_dictionary_color (self , kind ):
437
478
# issue-8193
438
479
# Test plot color dictionary format
439
480
data_files = ["a" , "b" ]
@@ -443,14 +484,11 @@ def test_dictionary_color(self):
443
484
df1 = DataFrame (np .random .rand (2 , 2 ), columns = data_files )
444
485
dic_color = {"b" : (0.3 , 0.7 , 0.7 ), "a" : (0.5 , 0.24 , 0.6 )}
445
486
446
- # Bar color test
447
- ax = df1 .plot (kind = "bar" , color = dic_color )
448
- colors = [rect .get_facecolor ()[0 :- 1 ] for rect in ax .get_children ()[0 :3 :2 ]]
449
- assert all (color == expected [index ] for index , color in enumerate (colors ))
450
-
451
- # Line color test
452
- ax = df1 .plot (kind = "line" , color = dic_color )
453
- colors = [rect .get_color () for rect in ax .get_lines ()[0 :2 ]]
487
+ ax = df1 .plot (kind = kind , color = dic_color )
488
+ if kind == "bar" :
489
+ colors = [rect .get_facecolor ()[0 :- 1 ] for rect in ax .get_children ()[0 :3 :2 ]]
490
+ else :
491
+ colors = [rect .get_color () for rect in ax .get_lines ()[0 :2 ]]
454
492
assert all (color == expected [index ] for index , color in enumerate (colors ))
455
493
456
494
def test_bar_plot (self ):
0 commit comments