Skip to content

Commit d98e08c

Browse files
committed
update create_violin docstring
1 parent 1d9c62c commit d98e08c

File tree

1 file changed

+44
-63
lines changed
  • packages/python/plotly/plotly/figure_factory

1 file changed

+44
-63
lines changed

packages/python/plotly/plotly/figure_factory/_violin.py

Lines changed: 44 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -449,126 +449,107 @@ def create_violin(
449449
title="Violin and Rug Plot",
450450
):
451451
"""
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
461461
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+
--------
488489
Example 1: Single Violin Plot
489490
490491
>>> from plotly.figure_factory import create_violin
491492
>>> import plotly.graph_objs as graph_objects
492-
493493
>>> import numpy as np
494494
>>> from scipy import stats
495-
496495
>>> # create list of random values
497496
>>> data_list = np.random.randn(100)
498-
499497
>>> # create violin fig
500498
>>> fig = create_violin(data_list, colors='#604d9e')
501-
502499
>>> # plot
503500
>>> fig.show()
504501
505502
Example 2: Multiple Violin Plots with Qualitative Coloring
506503
507504
>>> from plotly.figure_factory import create_violin
508505
>>> import plotly.graph_objs as graph_objects
509-
510506
>>> import numpy as np
511507
>>> import pandas as pd
512508
>>> from scipy import stats
513-
514509
>>> # create dataframe
515510
>>> np.random.seed(619517)
516-
>>> Nr=250
511+
>>> Nr = 250
517512
>>> y = np.random.randn(Nr)
518513
>>> 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)]
521515
>>> 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]
523517
>>> df = pd.DataFrame(dict(Score=y, Group=gr))
524-
525518
>>> # 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)
529520
>>> # plot
530521
>>> fig.show()
531522
532523
Example 3: Violin Plots with Colorscale
533524
534525
>>> from plotly.figure_factory import create_violin
535526
>>> import plotly.graph_objs as graph_objects
536-
537527
>>> import numpy as np
538528
>>> import pandas as pd
539529
>>> from scipy import stats
540-
541530
>>> # create dataframe
542531
>>> np.random.seed(619517)
543-
>>> Nr=250
532+
>>> Nr = 250
544533
>>> y = np.random.randn(Nr)
545534
>>> 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)]
548536
>>> 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]
550538
>>> df = pd.DataFrame(dict(Score=y, Group=gr))
551-
552539
>>> # define header params
553540
>>> data_header = 'Score'
554541
>>> group_header = 'Group'
555-
556542
>>> # make groupby object with pandas
557543
>>> group_stats = {}
558544
>>> groupby_data = df.groupby([group_header])
559-
560545
>>> for group in "ABCDE":
561546
... data_from_group = groupby_data.get_group(group)[data_header]
562547
... # take a stat of the grouped data
563548
... stat = np.median(data_from_group)
564549
... # add to dictionary
565550
... group_stats[group] = stat
566-
567551
>>> # 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)
572553
>>> # plot
573554
>>> fig.show()
574555
"""

0 commit comments

Comments
 (0)