Skip to content

add rugplot + changelog #670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## Unreleased
### Updated
- `plotly.figure_factory.create_violin()` now has a `rugplot` parameter which determines whether or not a rugplot is draw beside each violin plot.

## [2.0.0]

### Changed
Expand Down
47 changes: 26 additions & 21 deletions plotly/figure_factory/_violin.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ def violinplot(vals, fillcolor='#1f77b4', rugplot=True):


def violin_no_colorscale(data, data_header, group_header, colors,
use_colorscale, group_stats,
height, width, title):
use_colorscale, group_stats, rugplot,
height, width, title):
"""
Refer to FigureFactory.create_violin() for docstring.

Expand Down Expand Up @@ -223,7 +223,8 @@ def violin_no_colorscale(data, data_header, group_header, colors,
if color_index >= len(colors):
color_index = 0
plot_data, plot_xrange = violinplot(vals,
fillcolor=colors[color_index])
fillcolor=colors[color_index],
rugplot=rugplot)
layout = graph_objs.Layout()

for item in plot_data:
Expand All @@ -250,7 +251,7 @@ def violin_no_colorscale(data, data_header, group_header, colors,


def violin_colorscale(data, data_header, group_header, colors, use_colorscale,
group_stats, height, width, title):
group_stats, rugplot, height, width, title):
"""
Refer to FigureFactory.create_violin() for docstring.

Expand Down Expand Up @@ -303,7 +304,8 @@ def violin_colorscale(data, data_header, group_header, colors, use_colorscale,

plot_data, plot_xrange = violinplot(
vals,
fillcolor='rgb{}'.format(intermed_color)
fillcolor='rgb{}'.format(intermed_color),
rugplot=rugplot
)
layout = graph_objs.Layout()

Expand Down Expand Up @@ -343,7 +345,7 @@ def violin_colorscale(data, data_header, group_header, colors, use_colorscale,


def violin_dict(data, data_header, group_header, colors, use_colorscale,
group_stats, height, width, title):
group_stats, rugplot, height, width, title):
"""
Refer to FigureFactory.create_violin() for docstring.

Expand Down Expand Up @@ -375,7 +377,8 @@ def violin_dict(data, data_header, group_header, colors, use_colorscale,

for k, gr in enumerate(group_name):
vals = np.asarray(gb.get_group(gr)[data_header], np.float)
plot_data, plot_xrange = violinplot(vals, fillcolor=colors[gr])
plot_data, plot_xrange = violinplot(vals, fillcolor=colors[gr],
rugplot=rugplot)
layout = graph_objs.Layout()

for item in plot_data:
Expand All @@ -401,18 +404,18 @@ def violin_dict(data, data_header, group_header, colors, use_colorscale,


def create_violin(data, data_header=None, group_header=None, colors=None,
use_colorscale=False, group_stats=None, height=450,
width=600, title='Violin and Rug Plot'):
use_colorscale=False, group_stats=None, rugplot=True,
height=450, width=600, title='Violin and Rug Plot'):
"""
Returns figure for a violin plot

:param (list|array) data: accepts either a list of numerical values,
a list of dictionaries all with identical keys and at least one
column of numeric values, or a pandas dataframe with at least one
column of numbers
column of numbers.
:param (str) data_header: the header of the data column to be used
from an inputted pandas dataframe. Not applicable if 'data' is
a list of numeric values
a list of numeric values.
:param (str) group_header: applicable if grouping data by a variable.
'group_header' must be set to the name of the grouping variable.
:param (str|tuple|list|dict) colors: either a plotly scale name,
Expand All @@ -422,18 +425,19 @@ def create_violin(data, data_header=None, group_header=None, colors=None,
tuple of 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 its
members.
:param (bool) use_colorscale: Only applicable if grouping by another
:param (bool) use_colorscale: only applicable if grouping by another
variable. Will implement a colorscale based on the first 2 colors
of param colors. This means colors must be a list with at least 2
colors in it (Plotly colorscales are accepted since they map to a
list of two rgb colors)
list of two rgb colors).
:param (dict) group_stats: a dictioanry where each key is a unique
value from the group_header column in data. Each value must be a
number and will be used to color the violin plots if a colorscale
is being used
:param (float) height: the height of the violin plot
:param (float) width: the width of the violin plot
:param (str) title: the title of the violin plot
is being used.
:param (bool) rugplot: determines if a rugplot is draw on violin plot.
:param (float) height: the height of the violin plot.
:param (float) width: the width of the violin plot.
:param (str) title: the title of the violin plot.

Example 1: Single Violin Plot
```
Expand Down Expand Up @@ -558,7 +562,8 @@ def create_violin(data, data_header=None, group_header=None, colors=None,
data = data[data_header].values.tolist()

# call the plotting functions
plot_data, plot_xrange = violinplot(data, fillcolor=valid_colors[0])
plot_data, plot_xrange = violinplot(data, fillcolor=valid_colors[0],
rugplot=rugplot)

layout = graph_objs.Layout(
title=title,
Expand Down Expand Up @@ -596,13 +601,13 @@ def create_violin(data, data_header=None, group_header=None, colors=None,
# validate colors dict choice below
fig = violin_dict(
data, data_header, group_header, valid_colors,
use_colorscale, group_stats, height, width, title
use_colorscale, group_stats, rugplot, height, width, title
)
return fig
else:
fig = violin_no_colorscale(
data, data_header, group_header, valid_colors,
use_colorscale, group_stats, height, width, title
use_colorscale, group_stats, rugplot, height, width, title
)
return fig
else:
Expand All @@ -622,6 +627,6 @@ def create_violin(data, data_header=None, group_header=None, colors=None,

fig = violin_colorscale(
data, data_header, group_header, valid_colors,
use_colorscale, group_stats, height, width, title
use_colorscale, group_stats, rugplot, height, width, title
)
return fig