@@ -449,126 +449,107 @@ def create_violin(
449
449
title = "Violin and Rug Plot" ,
450
450
):
451
451
"""
452
- **deprecated**, use instead the plotly.graph_objects trace
453
- :class:`plotly.graph_objects.Violin`.
454
-
455
- :param (list|array) data: accepts either a list of numerical values,
456
- a list of dictionaries all with identical keys and at least one
457
- column of numeric values, or a pandas dataframe with at least one
458
- column of numbers.
459
- :param (str) data_header: the header of the data column to be used
460
- from an inputted pandas dataframe. Not applicable if 'data' is
452
+ **Deprecated**. Use [` plotly.graph_objects.Violin`][plotly.graph_objects.Violin] instead.
453
+
454
+ Parameters
455
+ ----------
456
+ data : list or array
457
+ Accepts either a list of numerical values, a list of dictionaries all with identical keys and at least one
458
+ column of numeric values, or a pandas dataframe with at least one column of numbers.
459
+ data_header : str
460
+ The header of the data column to be used from an inputted pandas dataframe. Not applicable if 'data' is
461
461
a list of numeric values.
462
- :param (str) group_header: applicable if grouping data by a variable.
463
- 'group_header' must be set to the name of the grouping variable.
464
- :param (str|tuple|list|dict) colors: either a plotly scale name,
465
- an rgb or hex color, a color tuple, a list of colors or a
466
- dictionary. An rgb color is of the form 'rgb(x, y, z)' where
467
- x, y and z belong to the interval [0, 255] and a color tuple is a
468
- tuple of the form (a, b, c) where a, b and c belong to [0, 1].
469
- If colors is a list, it must contain valid color types as its
470
- members.
471
- :param (bool) use_colorscale: only applicable if grouping by another
472
- variable. Will implement a colorscale based on the first 2 colors
473
- of param colors. This means colors must be a list with at least 2
474
- colors in it (Plotly colorscales are accepted since they map to a
475
- list of two rgb colors). Default = False
476
- :param (dict) group_stats: a dictionary where each key is a unique
477
- value from the group_header column in data. Each value must be a
478
- number and will be used to color the violin plots if a colorscale
479
- is being used.
480
- :param (bool) rugplot: determines if a rugplot is draw on violin plot.
481
- Default = True
482
- :param (bool) sort: determines if violins are sorted
483
- alphabetically (True) or by input order (False). Default = False
484
- :param (float) height: the height of the violin plot.
485
- :param (float) width: the width of the violin plot.
486
- :param (str) title: the title of the violin plot.
487
-
462
+ group_header : str
463
+ Applicable if grouping data by a variable. 'group_header' must be set to the name of the grouping variable.
464
+ colors : str, tuple, list, or dict
465
+ Either a plotly scale name, an rgb or hex color, a color tuple, a list of colors or a dictionary. An rgb color
466
+ is of the form 'rgb(x, y, z)' where x, y and z belong to the interval [0, 255] and a color tuple is a tuple of
467
+ the form (a, b, c) where a, b and c belong to [0, 1]. If colors is a list, it must contain valid color types as
468
+ its members.
469
+ use_colorscale : bool
470
+ Only applicable if grouping by another variable. Will implement a colorscale based on the first 2 colors
471
+ of param colors. This means colors must be a list with at least 2 colors in it (Plotly colorscales are accepted
472
+ since they map to a list of two rgb colors). Default is False.
473
+ group_stats : dict
474
+ A dictionary where each key is a unique value from the group_header column in data. Each value must be a
475
+ number and will be used to color the violin plots if a colorscale is being used.
476
+ rugplot : bool
477
+ Determines if a rugplot is drawn on the violin plot. Default is True.
478
+ sort : bool
479
+ Determines if violins are sorted alphabetically (True) or by input order (False). Default is False.
480
+ height : float
481
+ The height of the violin plot.
482
+ width : float
483
+ The width of the violin plot.
484
+ title : str
485
+ The title of the violin plot.
486
+
487
+ Examples
488
+ --------
488
489
Example 1: Single Violin Plot
489
490
490
491
>>> from plotly.figure_factory import create_violin
491
492
>>> import plotly.graph_objs as graph_objects
492
-
493
493
>>> import numpy as np
494
494
>>> from scipy import stats
495
-
496
495
>>> # create list of random values
497
496
>>> data_list = np.random.randn(100)
498
-
499
497
>>> # create violin fig
500
498
>>> fig = create_violin(data_list, colors='#604d9e')
501
-
502
499
>>> # plot
503
500
>>> fig.show()
504
501
505
502
Example 2: Multiple Violin Plots with Qualitative Coloring
506
503
507
504
>>> from plotly.figure_factory import create_violin
508
505
>>> import plotly.graph_objs as graph_objects
509
-
510
506
>>> import numpy as np
511
507
>>> import pandas as pd
512
508
>>> from scipy import stats
513
-
514
509
>>> # create dataframe
515
510
>>> np.random.seed(619517)
516
- >>> Nr= 250
511
+ >>> Nr = 250
517
512
>>> y = np.random.randn(Nr)
518
513
>>> gr = np.random.choice(list("ABCDE"), Nr)
519
- >>> norm_params=[(0, 1.2), (0.7, 1), (-0.5, 1.4), (0.3, 1), (0.8, 0.9)]
520
-
514
+ >>> norm_params = [(0, 1.2), (0.7, 1), (-0.5, 1.4), (0.3, 1), (0.8, 0.9)]
521
515
>>> for i, letter in enumerate("ABCDE"):
522
- ... y[gr == letter] *=norm_params[i][1]+ norm_params[i][0]
516
+ ... y[gr == letter] *= norm_params[i][1] + norm_params[i][0]
523
517
>>> df = pd.DataFrame(dict(Score=y, Group=gr))
524
-
525
518
>>> # create violin fig
526
- >>> fig = create_violin(df, data_header='Score', group_header='Group',
527
- ... sort=True, height=600, width=1000)
528
-
519
+ >>> fig = create_violin(df, data_header='Score', group_header='Group', sort=True, height=600, width=1000)
529
520
>>> # plot
530
521
>>> fig.show()
531
522
532
523
Example 3: Violin Plots with Colorscale
533
524
534
525
>>> from plotly.figure_factory import create_violin
535
526
>>> import plotly.graph_objs as graph_objects
536
-
537
527
>>> import numpy as np
538
528
>>> import pandas as pd
539
529
>>> from scipy import stats
540
-
541
530
>>> # create dataframe
542
531
>>> np.random.seed(619517)
543
- >>> Nr= 250
532
+ >>> Nr = 250
544
533
>>> y = np.random.randn(Nr)
545
534
>>> gr = np.random.choice(list("ABCDE"), Nr)
546
- >>> norm_params=[(0, 1.2), (0.7, 1), (-0.5, 1.4), (0.3, 1), (0.8, 0.9)]
547
-
535
+ >>> norm_params = [(0, 1.2), (0.7, 1), (-0.5, 1.4), (0.3, 1), (0.8, 0.9)]
548
536
>>> for i, letter in enumerate("ABCDE"):
549
- ... y[gr == letter] *=norm_params[i][1]+ norm_params[i][0]
537
+ ... y[gr == letter] *= norm_params[i][1] + norm_params[i][0]
550
538
>>> df = pd.DataFrame(dict(Score=y, Group=gr))
551
-
552
539
>>> # define header params
553
540
>>> data_header = 'Score'
554
541
>>> group_header = 'Group'
555
-
556
542
>>> # make groupby object with pandas
557
543
>>> group_stats = {}
558
544
>>> groupby_data = df.groupby([group_header])
559
-
560
545
>>> for group in "ABCDE":
561
546
... data_from_group = groupby_data.get_group(group)[data_header]
562
547
... # take a stat of the grouped data
563
548
... stat = np.median(data_from_group)
564
549
... # add to dictionary
565
550
... group_stats[group] = stat
566
-
567
551
>>> # create violin fig
568
- >>> fig = create_violin(df, data_header='Score', group_header='Group',
569
- ... height=600, width=1000, use_colorscale=True,
570
- ... group_stats=group_stats)
571
-
552
+ >>> fig = create_violin(df, data_header='Score', group_header='Group', height=600, width=1000, use_colorscale=True, group_stats=group_stats)
572
553
>>> # plot
573
554
>>> fig.show()
574
555
"""
0 commit comments