8
8
9
9
import numpy as np
10
10
11
- from pandas .util .decorators import cache_readonly
11
+ from pandas .util .decorators import cache_readonly , deprecate_kwarg
12
12
import pandas .core .common as com
13
13
from pandas .core .index import MultiIndex
14
14
from pandas .core .series import Series , remove_na
@@ -355,18 +355,22 @@ def _get_marker_compat(marker):
355
355
return marker
356
356
357
357
358
- def radviz (frame , class_column , ax = None , colormap = None , ** kwds ):
358
+ def radviz (frame , class_column , ax = None , color = None , colormap = None , ** kwds ):
359
359
"""RadViz - a multivariate data visualization algorithm
360
360
361
361
Parameters:
362
362
-----------
363
- frame: DataFrame object
364
- class_column: Column name that contains information about class membership
363
+ frame: DataFrame
364
+ class_column: str
365
+ Column name containing class names
365
366
ax: Matplotlib axis object, optional
367
+ color: list or tuple, optional
368
+ Colors to use for the different classes
366
369
colormap : str or matplotlib colormap object, default None
367
370
Colormap to select colors from. If string, load colormap with that name
368
371
from matplotlib.
369
- kwds: Matplotlib scatter method keyword arguments, optional
372
+ kwds: keywords
373
+ Options to pass to matplotlib scatter plotting method
370
374
371
375
Returns:
372
376
--------
@@ -380,44 +384,42 @@ def normalize(series):
380
384
b = max (series )
381
385
return (series - a ) / (b - a )
382
386
383
- column_names = [ column_name for column_name in frame . columns
384
- if column_name != class_column ]
385
-
386
- df = frame [ column_names ] .apply (normalize )
387
+ n = len ( frame )
388
+ classes = frame [ class_column ]. drop_duplicates ()
389
+ class_col = frame [ class_column ]
390
+ df = frame . drop ( class_column , axis = 1 ) .apply (normalize )
387
391
388
392
if ax is None :
389
393
ax = plt .gca (xlim = [- 1 , 1 ], ylim = [- 1 , 1 ])
390
394
391
- classes = set (frame [class_column ])
392
395
to_plot = {}
393
-
394
396
colors = _get_standard_colors (num_colors = len (classes ), colormap = colormap ,
395
- color_type = 'random' , color = kwds . get ( ' color' ) )
397
+ color_type = 'random' , color = color )
396
398
397
- for class_ in classes :
398
- to_plot [class_ ] = [[], []]
399
+ for kls in classes :
400
+ to_plot [kls ] = [[], []]
399
401
400
402
n = len (frame .columns ) - 1
401
403
s = np .array ([(np .cos (t ), np .sin (t ))
402
404
for t in [2.0 * np .pi * (i / float (n ))
403
405
for i in range (n )]])
404
406
405
- for i in range (len ( frame ) ):
406
- row = df .irow ( i ) .values
407
+ for i in range (n ):
408
+ row = df .iloc [ i ] .values
407
409
row_ = np .repeat (np .expand_dims (row , axis = 1 ), 2 , axis = 1 )
408
410
y = (s * row_ ).sum (axis = 0 ) / row .sum ()
409
- class_name = frame [ class_column ]. iget ( i )
410
- to_plot [class_name ][0 ].append (y [0 ])
411
- to_plot [class_name ][1 ].append (y [1 ])
411
+ kls = class_col . iat [ i ]
412
+ to_plot [kls ][0 ].append (y [0 ])
413
+ to_plot [kls ][1 ].append (y [1 ])
412
414
413
- for i , class_ in enumerate (classes ):
414
- ax .scatter (to_plot [class_ ][0 ], to_plot [class_ ][1 ], color = colors [i ],
415
- label = com .pprint_thing (class_ ), ** kwds )
415
+ for i , kls in enumerate (classes ):
416
+ ax .scatter (to_plot [kls ][0 ], to_plot [kls ][1 ], color = colors [i ],
417
+ label = com .pprint_thing (kls ), ** kwds )
416
418
ax .legend ()
417
419
418
420
ax .add_patch (patches .Circle ((0.0 , 0.0 ), radius = 1.0 , facecolor = 'none' ))
419
421
420
- for xy , name in zip (s , column_names ):
422
+ for xy , name in zip (s , df . columns ):
421
423
422
424
ax .add_patch (patches .Circle (xy , radius = 0.025 , facecolor = 'gray' ))
423
425
@@ -438,20 +440,23 @@ def normalize(series):
438
440
return ax
439
441
440
442
441
- def andrews_curves (data , class_column , ax = None , samples = 200 , colormap = None ,
442
- ** kwds ):
443
+ def andrews_curves (frame , class_column , ax = None , samples = 200 , color = None ,
444
+ colormap = None , ** kwds ):
443
445
"""
444
446
Parameters:
445
447
-----------
446
- data : DataFrame
448
+ frame : DataFrame
447
449
Data to be plotted, preferably normalized to (0.0, 1.0)
448
450
class_column : Name of the column containing class names
449
451
ax : matplotlib axes object, default None
450
452
samples : Number of points to plot in each curve
453
+ color: list or tuple, optional
454
+ Colors to use for the different classes
451
455
colormap : str or matplotlib colormap object, default None
452
456
Colormap to select colors from. If string, load colormap with that name
453
457
from matplotlib.
454
- kwds : Optional plotting arguments to be passed to matplotlib
458
+ kwds: keywords
459
+ Options to pass to matplotlib plotting method
455
460
456
461
Returns:
457
462
--------
@@ -475,30 +480,31 @@ def f(x):
475
480
return result
476
481
return f
477
482
478
- n = len (data )
479
- class_col = data [class_column ]
480
- uniq_class = class_col .drop_duplicates ()
481
- columns = [ data [ col ] for col in data . columns if ( col != class_column )]
483
+ n = len (frame )
484
+ class_col = frame [class_column ]
485
+ classes = frame [ class_column ] .drop_duplicates ()
486
+ df = frame . drop ( class_column , axis = 1 )
482
487
x = [- pi + 2.0 * pi * (t / float (samples )) for t in range (samples )]
483
488
used_legends = set ([])
484
489
485
- colors = _get_standard_colors (num_colors = len (uniq_class ), colormap = colormap ,
486
- color_type = 'random' , color = kwds .get ('color' ))
487
- col_dict = dict ([(klass , col ) for klass , col in zip (uniq_class , colors )])
490
+ color_values = _get_standard_colors (num_colors = len (classes ),
491
+ colormap = colormap , color_type = 'random' ,
492
+ color = color )
493
+ colors = dict (zip (classes , color_values ))
488
494
if ax is None :
489
495
ax = plt .gca (xlim = (- pi , pi ))
490
496
for i in range (n ):
491
- row = [ columns [ c ][ i ] for c in range ( len ( columns ))]
497
+ row = df . iloc [ i ]. values
492
498
f = function (row )
493
499
y = [f (t ) for t in x ]
494
- label = None
495
- if com .pprint_thing (class_col [ i ]) not in used_legends :
496
- label = com . pprint_thing ( class_col [ i ])
500
+ kls = class_col . iat [ i ]
501
+ label = com .pprint_thing (kls )
502
+ if label not in used_legends :
497
503
used_legends .add (label )
498
- ax .plot (x , y , color = col_dict [ class_col [ i ] ], label = label , ** kwds )
504
+ ax .plot (x , y , color = colors [ kls ], label = label , ** kwds )
499
505
else :
500
- ax .plot (x , y , color = col_dict [ class_col [ i ] ], ** kwds )
501
-
506
+ ax .plot (x , y , color = colors [ kls ], ** kwds )
507
+
502
508
ax .legend (loc = 'upper right' )
503
509
ax .grid ()
504
510
return ax
@@ -564,31 +570,31 @@ def bootstrap_plot(series, fig=None, size=50, samples=500, **kwds):
564
570
plt .setp (axis .get_yticklabels (), fontsize = 8 )
565
571
return fig
566
572
567
-
568
- def parallel_coordinates (data , class_column , cols = None , ax = None , colors = None ,
569
- use_columns = False , xticks = None , colormap = None , ** kwds ):
573
+ @deprecate_kwarg (old_arg_name = 'colors' , new_arg_name = 'color' )
574
+ def parallel_coordinates (frame , class_column , cols = None , ax = None , color = None ,
575
+ use_columns = False , xticks = None , colormap = None ,
576
+ ** kwds ):
570
577
"""Parallel coordinates plotting.
571
578
572
579
Parameters
573
580
----------
574
- data: DataFrame
575
- A DataFrame containing data to be plotted
581
+ frame: DataFrame
576
582
class_column: str
577
583
Column name containing class names
578
584
cols: list, optional
579
585
A list of column names to use
580
586
ax: matplotlib.axis, optional
581
587
matplotlib axis object
582
- colors : list or tuple, optional
588
+ color : list or tuple, optional
583
589
Colors to use for the different classes
584
590
use_columns: bool, optional
585
591
If true, columns will be used as xticks
586
592
xticks: list or tuple, optional
587
593
A list of values to use for xticks
588
594
colormap: str or matplotlib colormap, default None
589
595
Colormap to use for line colors.
590
- kwds: list, optional
591
- A list of keywords for matplotlib plot method
596
+ kwds: keywords
597
+ Options to pass to matplotlib plotting method
592
598
593
599
Returns
594
600
-------
@@ -600,20 +606,19 @@ def parallel_coordinates(data, class_column, cols=None, ax=None, colors=None,
600
606
>>> from pandas.tools.plotting import parallel_coordinates
601
607
>>> from matplotlib import pyplot as plt
602
608
>>> df = read_csv('https://raw.github.com/pydata/pandas/master/pandas/tests/data/iris.csv')
603
- >>> parallel_coordinates(df, 'Name', colors =('#556270', '#4ECDC4', '#C7F464'))
609
+ >>> parallel_coordinates(df, 'Name', color =('#556270', '#4ECDC4', '#C7F464'))
604
610
>>> plt.show()
605
611
"""
606
612
import matplotlib .pyplot as plt
607
613
608
-
609
- n = len (data )
610
- classes = set (data [class_column ])
611
- class_col = data [class_column ]
614
+ n = len (frame )
615
+ classes = frame [class_column ].drop_duplicates ()
616
+ class_col = frame [class_column ]
612
617
613
618
if cols is None :
614
- df = data .drop (class_column , axis = 1 )
619
+ df = frame .drop (class_column , axis = 1 )
615
620
else :
616
- df = data [cols ]
621
+ df = frame [cols ]
617
622
618
623
used_legends = set ([])
619
624
@@ -638,19 +643,17 @@ def parallel_coordinates(data, class_column, cols=None, ax=None, colors=None,
638
643
639
644
color_values = _get_standard_colors (num_colors = len (classes ),
640
645
colormap = colormap , color_type = 'random' ,
641
- color = colors )
646
+ color = color )
642
647
643
648
colors = dict (zip (classes , color_values ))
644
649
645
650
for i in range (n ):
646
- row = df .irow (i ).values
647
- y = row
648
- kls = class_col .iget_value (i )
649
- if com .pprint_thing (kls ) not in used_legends :
650
- label = com .pprint_thing (kls )
651
+ y = df .iloc [i ].values
652
+ kls = class_col .iat [i ]
653
+ label = com .pprint_thing (kls )
654
+ if label not in used_legends :
651
655
used_legends .add (label )
652
- ax .plot (x , y , color = colors [kls ],
653
- label = label , ** kwds )
656
+ ax .plot (x , y , color = colors [kls ], label = label , ** kwds )
654
657
else :
655
658
ax .plot (x , y , color = colors [kls ], ** kwds )
656
659
0 commit comments