@@ -194,8 +194,8 @@ def violinplot(vals, fillcolor='#1f77b4', rugplot=True):
194
194
195
195
196
196
def violin_no_colorscale (data , data_header , group_header , colors ,
197
- use_colorscale , group_stats ,
198
- height , width , title ):
197
+ use_colorscale , group_stats , rugplot ,
198
+ height , width , title ):
199
199
"""
200
200
Refer to FigureFactory.create_violin() for docstring.
201
201
@@ -223,7 +223,8 @@ def violin_no_colorscale(data, data_header, group_header, colors,
223
223
if color_index >= len (colors ):
224
224
color_index = 0
225
225
plot_data , plot_xrange = violinplot (vals ,
226
- fillcolor = colors [color_index ])
226
+ fillcolor = colors [color_index ],
227
+ rugplot = rugplot )
227
228
layout = graph_objs .Layout ()
228
229
229
230
for item in plot_data :
@@ -250,7 +251,7 @@ def violin_no_colorscale(data, data_header, group_header, colors,
250
251
251
252
252
253
def violin_colorscale (data , data_header , group_header , colors , use_colorscale ,
253
- group_stats , height , width , title ):
254
+ group_stats , rugplot , height , width , title ):
254
255
"""
255
256
Refer to FigureFactory.create_violin() for docstring.
256
257
@@ -303,7 +304,8 @@ def violin_colorscale(data, data_header, group_header, colors, use_colorscale,
303
304
304
305
plot_data , plot_xrange = violinplot (
305
306
vals ,
306
- fillcolor = 'rgb{}' .format (intermed_color )
307
+ fillcolor = 'rgb{}' .format (intermed_color ),
308
+ rugplot = rugplot
307
309
)
308
310
layout = graph_objs .Layout ()
309
311
@@ -343,7 +345,7 @@ def violin_colorscale(data, data_header, group_header, colors, use_colorscale,
343
345
344
346
345
347
def violin_dict (data , data_header , group_header , colors , use_colorscale ,
346
- group_stats , height , width , title ):
348
+ group_stats , rugplot , height , width , title ):
347
349
"""
348
350
Refer to FigureFactory.create_violin() for docstring.
349
351
@@ -375,7 +377,8 @@ def violin_dict(data, data_header, group_header, colors, use_colorscale,
375
377
376
378
for k , gr in enumerate (group_name ):
377
379
vals = np .asarray (gb .get_group (gr )[data_header ], np .float )
378
- plot_data , plot_xrange = violinplot (vals , fillcolor = colors [gr ])
380
+ plot_data , plot_xrange = violinplot (vals , fillcolor = colors [gr ],
381
+ rugplot = rugplot )
379
382
layout = graph_objs .Layout ()
380
383
381
384
for item in plot_data :
@@ -401,18 +404,18 @@ def violin_dict(data, data_header, group_header, colors, use_colorscale,
401
404
402
405
403
406
def create_violin (data , data_header = None , group_header = None , colors = None ,
404
- use_colorscale = False , group_stats = None , height = 450 ,
405
- width = 600 , title = 'Violin and Rug Plot' ):
407
+ use_colorscale = False , group_stats = None , rugplot = True ,
408
+ height = 450 , width = 600 , title = 'Violin and Rug Plot' ):
406
409
"""
407
410
Returns figure for a violin plot
408
411
409
412
:param (list|array) data: accepts either a list of numerical values,
410
413
a list of dictionaries all with identical keys and at least one
411
414
column of numeric values, or a pandas dataframe with at least one
412
- column of numbers
415
+ column of numbers.
413
416
:param (str) data_header: the header of the data column to be used
414
417
from an inputted pandas dataframe. Not applicable if 'data' is
415
- a list of numeric values
418
+ a list of numeric values.
416
419
:param (str) group_header: applicable if grouping data by a variable.
417
420
'group_header' must be set to the name of the grouping variable.
418
421
:param (str|tuple|list|dict) colors: either a plotly scale name,
@@ -422,18 +425,19 @@ def create_violin(data, data_header=None, group_header=None, colors=None,
422
425
tuple of the form (a, b, c) where a, b and c belong to [0, 1].
423
426
If colors is a list, it must contain valid color types as its
424
427
members.
425
- :param (bool) use_colorscale: Only applicable if grouping by another
428
+ :param (bool) use_colorscale: only applicable if grouping by another
426
429
variable. Will implement a colorscale based on the first 2 colors
427
430
of param colors. This means colors must be a list with at least 2
428
431
colors in it (Plotly colorscales are accepted since they map to a
429
- list of two rgb colors)
432
+ list of two rgb colors).
430
433
:param (dict) group_stats: a dictioanry where each key is a unique
431
434
value from the group_header column in data. Each value must be a
432
435
number and will be used to color the violin plots if a colorscale
433
- is being used
434
- :param (float) height: the height of the violin plot
435
- :param (float) width: the width of the violin plot
436
- :param (str) title: the title of the violin plot
436
+ is being used.
437
+ :param (bool) rugplot: determines if a rugplot is draw on violin plot.
438
+ :param (float) height: the height of the violin plot.
439
+ :param (float) width: the width of the violin plot.
440
+ :param (str) title: the title of the violin plot.
437
441
438
442
Example 1: Single Violin Plot
439
443
```
@@ -558,7 +562,8 @@ def create_violin(data, data_header=None, group_header=None, colors=None,
558
562
data = data [data_header ].values .tolist ()
559
563
560
564
# call the plotting functions
561
- plot_data , plot_xrange = violinplot (data , fillcolor = valid_colors [0 ])
565
+ plot_data , plot_xrange = violinplot (data , fillcolor = valid_colors [0 ],
566
+ rugplot = rugplot )
562
567
563
568
layout = graph_objs .Layout (
564
569
title = title ,
@@ -596,13 +601,13 @@ def create_violin(data, data_header=None, group_header=None, colors=None,
596
601
# validate colors dict choice below
597
602
fig = violin_dict (
598
603
data , data_header , group_header , valid_colors ,
599
- use_colorscale , group_stats , height , width , title
604
+ use_colorscale , group_stats , rugplot , height , width , title
600
605
)
601
606
return fig
602
607
else :
603
608
fig = violin_no_colorscale (
604
609
data , data_header , group_header , valid_colors ,
605
- use_colorscale , group_stats , height , width , title
610
+ use_colorscale , group_stats , rugplot , height , width , title
606
611
)
607
612
return fig
608
613
else :
@@ -622,6 +627,6 @@ def create_violin(data, data_header=None, group_header=None, colors=None,
622
627
623
628
fig = violin_colorscale (
624
629
data , data_header , group_header , valid_colors ,
625
- use_colorscale , group_stats , height , width , title
630
+ use_colorscale , group_stats , rugplot , height , width , title
626
631
)
627
632
return fig
0 commit comments