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
@@ -354,19 +354,22 @@ def _get_marker_compat(marker):
354
354
return 'o'
355
355
return marker
356
356
357
-
358
- def radviz (frame , class_column , ax = None , colormap = None , ** kwds ):
357
+ def radviz (frame , class_column , ax = None , color = None , colormap = None , ** kwds ):
359
358
"""RadViz - a multivariate data visualization algorithm
360
359
361
360
Parameters:
362
361
-----------
363
- frame: DataFrame object
364
- class_column: Column name that contains information about class membership
362
+ frame: DataFrame
363
+ class_column: str
364
+ Column name containing class names
365
365
ax: Matplotlib axis object, optional
366
+ color: list or tuple, optional
367
+ Colors to use for the different classes
366
368
colormap : str or matplotlib colormap object, default None
367
369
Colormap to select colors from. If string, load colormap with that name
368
370
from matplotlib.
369
- kwds: Matplotlib scatter method keyword arguments, optional
371
+ kwds: keywords
372
+ Options to pass to matplotlib scatter plotting method
370
373
371
374
Returns:
372
375
--------
@@ -380,44 +383,42 @@ def normalize(series):
380
383
b = max (series )
381
384
return (series - a ) / (b - a )
382
385
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 )
386
+ n = len ( frame )
387
+ classes = frame [ class_column ]. drop_duplicates ()
388
+ class_col = frame [ class_column ]
389
+ df = frame . drop ( class_column , axis = 1 ) .apply (normalize )
387
390
388
391
if ax is None :
389
392
ax = plt .gca (xlim = [- 1 , 1 ], ylim = [- 1 , 1 ])
390
393
391
- classes = set (frame [class_column ])
392
394
to_plot = {}
393
-
394
395
colors = _get_standard_colors (num_colors = len (classes ), colormap = colormap ,
395
- color_type = 'random' , color = kwds . get ( ' color' ) )
396
+ color_type = 'random' , color = color )
396
397
397
- for class_ in classes :
398
- to_plot [class_ ] = [[], []]
398
+ for kls in classes :
399
+ to_plot [kls ] = [[], []]
399
400
400
401
n = len (frame .columns ) - 1
401
402
s = np .array ([(np .cos (t ), np .sin (t ))
402
403
for t in [2.0 * np .pi * (i / float (n ))
403
404
for i in range (n )]])
404
405
405
- for i in range (len ( frame ) ):
406
- row = df .irow ( i ) .values
406
+ for i in range (n ):
407
+ row = df .iloc [ i ] .values
407
408
row_ = np .repeat (np .expand_dims (row , axis = 1 ), 2 , axis = 1 )
408
409
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 ])
410
+ kls = class_col . iat [ i ]
411
+ to_plot [kls ][0 ].append (y [0 ])
412
+ to_plot [kls ][1 ].append (y [1 ])
412
413
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 )
414
+ for i , kls in enumerate (classes ):
415
+ ax .scatter (to_plot [kls ][0 ], to_plot [kls ][1 ], color = colors [i ],
416
+ label = com .pprint_thing (kls ), ** kwds )
416
417
ax .legend ()
417
418
418
419
ax .add_patch (patches .Circle ((0.0 , 0.0 ), radius = 1.0 , facecolor = 'none' ))
419
420
420
- for xy , name in zip (s , column_names ):
421
+ for xy , name in zip (s , df . columns ):
421
422
422
423
ax .add_patch (patches .Circle (xy , radius = 0.025 , facecolor = 'gray' ))
423
424
@@ -437,21 +438,24 @@ def normalize(series):
437
438
ax .axis ('equal' )
438
439
return ax
439
440
440
-
441
- def andrews_curves (data , class_column , ax = None , samples = 200 , colormap = None ,
442
- ** kwds ):
441
+ @ deprecate_kwarg ( old_arg_name = 'data' , new_arg_name = 'frame' )
442
+ def andrews_curves (frame , class_column , ax = None , samples = 200 , color = None ,
443
+ colormap = None , ** kwds ):
443
444
"""
444
445
Parameters:
445
446
-----------
446
- data : DataFrame
447
+ frame : DataFrame
447
448
Data to be plotted, preferably normalized to (0.0, 1.0)
448
449
class_column : Name of the column containing class names
449
450
ax : matplotlib axes object, default None
450
451
samples : Number of points to plot in each curve
452
+ color: list or tuple, optional
453
+ Colors to use for the different classes
451
454
colormap : str or matplotlib colormap object, default None
452
455
Colormap to select colors from. If string, load colormap with that name
453
456
from matplotlib.
454
- kwds : Optional plotting arguments to be passed to matplotlib
457
+ kwds: keywords
458
+ Options to pass to matplotlib plotting method
455
459
456
460
Returns:
457
461
--------
@@ -475,30 +479,31 @@ def f(x):
475
479
return result
476
480
return f
477
481
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 )]
482
+ n = len (frame )
483
+ class_col = frame [class_column ]
484
+ classes = frame [ class_column ] .drop_duplicates ()
485
+ df = frame . drop ( class_column , axis = 1 )
482
486
x = [- pi + 2.0 * pi * (t / float (samples )) for t in range (samples )]
483
487
used_legends = set ([])
484
488
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 )])
489
+ color_values = _get_standard_colors (num_colors = len (classes ),
490
+ colormap = colormap , color_type = 'random' ,
491
+ color = color )
492
+ colors = dict (zip (classes , color_values ))
488
493
if ax is None :
489
494
ax = plt .gca (xlim = (- pi , pi ))
490
495
for i in range (n ):
491
- row = [ columns [ c ][ i ] for c in range ( len ( columns ))]
496
+ row = df . iloc [ i ]. values
492
497
f = function (row )
493
498
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 ])
499
+ kls = class_col . iat [ i ]
500
+ label = com .pprint_thing (kls )
501
+ if label not in used_legends :
497
502
used_legends .add (label )
498
- ax .plot (x , y , color = col_dict [ class_col [ i ] ], label = label , ** kwds )
503
+ ax .plot (x , y , color = colors [ kls ], label = label , ** kwds )
499
504
else :
500
- ax .plot (x , y , color = col_dict [ class_col [ i ] ], ** kwds )
501
-
505
+ ax .plot (x , y , color = colors [ kls ], ** kwds )
506
+
502
507
ax .legend (loc = 'upper right' )
503
508
ax .grid ()
504
509
return ax
@@ -564,31 +569,32 @@ def bootstrap_plot(series, fig=None, size=50, samples=500, **kwds):
564
569
plt .setp (axis .get_yticklabels (), fontsize = 8 )
565
570
return fig
566
571
567
-
568
- def parallel_coordinates (data , class_column , cols = None , ax = None , colors = None ,
569
- use_columns = False , xticks = None , colormap = None , ** kwds ):
572
+ @deprecate_kwarg (old_arg_name = 'colors' , new_arg_name = 'color' )
573
+ @deprecate_kwarg (old_arg_name = 'data' , new_arg_name = 'frame' )
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