Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Violin #471

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
Kully merged 28 commits into master from Violin
Jun 14, 2016
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
651e725
Changed tools.py
Kully May 18, 2016
b4eb690
Updated tools.py again
Kully May 18, 2016
2530527
...
Kully May 18, 2016
85710a6
Improved tools.py
Kully May 20, 2016
352d233
First PR for Violin: colorscaling, visible colorscale, all color-type...
Kully May 20, 2016
e29e7d3
Updated default-schema
Kully Jun 2, 2016
bde9a7c
Updated color parsing functions
Kully Jun 2, 2016
4257ed6
Added changes
Kully Jun 2, 2016
b0ff4d2
...
Kully Jun 3, 2016
06d685d
added more things
Kully Jun 3, 2016
13b5ba7
more
Kully Jun 5, 2016
a69c4bd
Violin with qualitative colors//updated tests
Kully Jun 5, 2016
a6ce8e3
re-did tests
Kully Jun 5, 2016
9a20ece
Add a description line
Kully Jun 5, 2016
d3059e0
added tests//added group labels to plots//edited main doc string
Kully Jun 6, 2016
ce6f83a
Added/updated doc string examples
Kully Jun 6, 2016
164a9c6
accurate colorscale max/min labels
Kully Jun 6, 2016
4abec6e
Made error messages more legible
Kully Jun 8, 2016
6bd112b
Moved PLOTLY_SCALES to top of file
Kully Jun 8, 2016
5900590
...
Kully Jun 8, 2016
11da292
..
Kully Jun 8, 2016
536ab35
wrote method for dealing with different color formats (eg. list, tupl...
Kully Jun 8, 2016
4904ac5
added color_parser function//removed dictionary capbilities
Kully Jun 10, 2016
d0f55cf
Replaced DEFAULT_FILLCOLOR with fillcolor param in functions
Kully Jun 13, 2016
4a954e1
Merged master into Violin
Kully Jun 13, 2016
d319448
Made tests compatible with color_parser code
Kully Jun 13, 2016
303385d
Replaced new color_parser function into scatterplot_theme
Kully Jun 14, 2016
c24b374
Removed commented out code and removed brackets from 'if colors[index...
Kully Jun 14, 2016
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
Prev Previous commit
Next Next commit
added more things
  • Loading branch information
Kully committed Jun 3, 2016
commit 06d685d0e918654d8eac48b33787bb787bd94b9c
202 changes: 130 additions & 72 deletions plotly/tools.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1477,8 +1477,6 @@ def _make_half_violin(x, y, fillcolor='#1f77b4', linecolor='rgb(0,0,0)'):
"""
Produces a sideways probability distribution fig violin plot.
"""


from plotly.graph_objs import graph_objs

text = ['(pdf(y), y)=(' + '{:0.2f}'.format(x[i]) +
Expand Down Expand Up @@ -1650,7 +1648,6 @@ def _violin_no_colorscale(data, data_header, colors, use_colorscale,
Returns fig for violin plot without colorscale.

"""

from plotly.graph_objs import graph_objs
import numpy as np

Expand Down Expand Up @@ -1791,7 +1788,6 @@ def _violin_dict(data, data_header, colors, use_colorscale,
Returns fig for violin plot without colorscale.

"""

from plotly.graph_objs import graph_objs
import numpy as np

Expand All @@ -1809,20 +1805,17 @@ def _violin_dict(data, data_header, colors, use_colorscale,
shared_yaxes=True,
horizontal_spacing=0.025,
print_grid=True)
color_index = 0

for k, gr in enumerate(group_name):
vals = np.asarray(gb.get_group(gr)[data_header], np.float)
if color_index >= len(colors):
color_index = 0
plot_data, plot_xrange = FigureFactory._violinplot(
vals,
fillcolor=colors[color_index]
fillcolor=colors[gr]
)
layout = graph_objs.Layout()

for item in plot_data:
fig.append_trace(item, 1, k + 1)
color_index += 1
# set the sharey axis style
fig['layout'].update(
{'yaxis{}'.format(1): FigureFactory._make_YAxis('')}
Expand Down Expand Up @@ -1852,8 +1845,7 @@ def create_violin(data, data_header=None, colors=None,
: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
:param (str|list) colors: either a rgb or hex color-string or a list
of color-strings
:param (str|list|dict) colors: **import proper doc string description**
:param (bool) use_colorscale: will implement a colorscale based on the
first 2 color strings of 'colors' if a list. Only applicable if
grouping by another variable
Expand Down Expand Up @@ -1937,35 +1929,106 @@ def create_violin(data, data_header=None, colors=None,
'Electric': ['rgb(0,0,0)', 'rgb(255,250,220)'],
'Viridis': ['rgb(68,1,84)', 'rgb(253,231,37)']}
Copy link
Contributor

@theengineear theengineear Jun 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, did we discuss moving this to a constant? Seems weird to create this. Maybe we should create a colors.py file for things like this?


# validate colors
# Validate colors
if colors is None:
colors = DEFAULT_PLOTLY_COLORS

if isinstance(colors, str):
if colors in plotly_scales:
colors = plotly_scales[colors]
else:
if ('rgb' not in colors) and ('#' not in colors):
raise exceptions.PlotlyError("If you input a string "
"for 'colors', it must "
"either be a Plotly "
"colorscale, an 'rgb' "
"color, or a hex color.")

elif 'rgb' in colors:
# validate rgb color
colors = FigureFactory._unlabel_rgb(colors)
for value in colors:
if value > 255.0:
raise exceptions.PlotlyError("Whoops! The "
"elements in your "
"rgb colors "
"tuples cannot "
"exceed 255.0.")
Copy link
Contributor

@theengineear theengineear Jun 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐄 in general, your code ends up taking more lines than it needs to. Here, I'd suggest:

raise exception.PlotlyError(
 "Whoops! The elements in your rgb colors "
 "tuples cannot exceed 255.0."
)

It only saves a line in this case, but I think it also improves readability.

colors = FigureFactory._label_rgb(colors)

# put colors in list
colors_list = []
colors_list.append(colors)
colors = colors_list

if not isinstance(colors, list):
raise exceptions.PlotlyError("'colors' needs to be either a "
"plotly colorscale string or a "
"list of at least two colors if "
"use_colorscale is True.")
if len(colors) <= 0:
raise exceptions.PlotlyError("Empty list of colors.")
elif '#' in colors:
colors = FigureFactory._hex_to_rgb(colors)
colors = FigureFactory._label_rgb(colors)

if (not isinstance(data, list)) and data_header is None:
raise exceptions.PlotlyError("Please enter a string name for "
"data_header")
# put colors in list
colors_list = []
colors_list.append(colors)
colors = colors_list

else:
scale_keys = list(plotly_scales.keys())
raise exceptions.PlotlyError("If you input a string "
"for 'colors', it must "
"either be a Plotly "
"colorscale, an 'rgb' "
"color or a hex color."
"Valid plotly colorscale "
"names are {}".format(scale_keys))
Copy link
Contributor

@theengineear theengineear Jun 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐄 Ditto, here, just start a new line and save a couple lines.

elif isinstance(colors, tuple):
# validate tuple color
for value in colors:
if value > 1.0:
raise exceptions.PlotlyError("Whoops! The "
"elements in "
"your colors "
"tuples cannot "
"exceed 1.0.")
Copy link
Contributor

@theengineear theengineear Jun 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐄 reformat this.


colors = FigureFactory._convert_to_RGB_255(colors)
colors = FigureFactory._label_rgb(colors)

colors_list = []
colors_list.append(colors)
colors = colors_list

elif isinstance(colors, list):
new_colormap = []
for color in colors:
if 'rgb' in color:
Copy link
Contributor

@theengineear theengineear Jun 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be more 🐫 (DRY). Why don't you make colors a list right in the beginning? Does that make sense?

color = FigureFactory._unlabel_rgb(color)
for value in color:
if value > 255.0:
raise exceptions.PlotlyError("Whoops! The "
"elements in your "
"rgb colors "
"tuples cannot "
"exceed 255.0.")

color = FigureFactory._label_rgb(color)
new_colormap.append(color)
elif '#' in color:
color = FigureFactory._hex_to_rgb(color)
color = FigureFactory._label_rgb(color)
new_colormap.append(color)
elif isinstance(color, tuple):
for value in color:
if value > 1.0:
raise exceptions.PlotlyError("Whoops! The "
"elements in "
"your colors "
"tuples cannot "
"exceed 1.0.")
new_colormap.append(color)
colors = new_colormap

elif isinstance(colors, dict):
pass
# validate dict

else:
raise exceptions.PlotlyError("You must input a valid colors "
"choice. Valid types include a "
"plotly scale, rgb, hex or tuple "
"color, a list of any color types "
"or a dictionary.")

# validate data and choose plot type
if group_header is None:
Expand All @@ -1975,17 +2038,10 @@ def create_violin(data, data_header=None, colors=None,
"nonempty and contain either "
"numbers or dictionaries.")

if isinstance(data[0], dict):
data_list = []
for dictionary in data:
data_list.append(dictionary[data_header])
data = data_list

if not isinstance(data[0], Number):
raise exceptions.PlotlyError("If data is a list, it must "
"contain either numbers or "
"dictionaries.")

"contain only numbers.")
# fix up for test: add 'if pandas_imported', etc
if isinstance(data, pd.core.frame.DataFrame):
data = data[data_header].values.tolist()

Expand Down Expand Up @@ -2013,42 +2069,44 @@ def create_violin(data, data_header=None, colors=None,
return fig

else:
if isinstance(data, list):
if len(data) <= 0:
raise exceptions.PlotlyError("If data is a list and "
"group_by is not None, then "
"data must be either a list "
"of dictionaries or a data"
"frame.")
if not isinstance(data, pd.core.frame.DataFrame):
raise exceptions.PlotlyError("Error.")

if isinstance(data, pd.core.frame.DataFrame):
if use_colorscale is False:
fig = FigureFactory._violin_no_colorscale(data,
data_header,
colors,
use_colorscale,
group_header,
height,
width,
title)
return fig
if isinstance(colors, dict):
# validate colors dict choice below

else:
# check if colors is a list of at least two colors
if len(colors) < 2:
raise exceptions.PlotlyError("If you are using color"
"scale, 'colors' must "
"be a list of at least "
"2 color-strings.")
fig = FigureFactory._violin_colorscale(data,
data_header,
colors,
use_colorscale,
group_header,
height,
width,
title)
return fig
fig = FigureFactory._violin_dict(data, data_header, colors,
use_colorscale, group_header,
height, width, title)
return fig

if use_colorscale is False:
fig = FigureFactory._violin_no_colorscale(data,
data_header,
colors,
use_colorscale,
group_header,
height,
width,
title)
return fig

else:
# check if colors is a list of at least two colors
if len(colors) < 2:
raise exceptions.PlotlyError("If you are using color"
"scale, 'colors' must "
"be a list of at least "
"2 color-strings.")
fig = FigureFactory._violin_colorscale(data,
data_header,
colors,
use_colorscale,
group_header,
height,
width,
title)
Copy link
Contributor

@theengineear theengineear Jun 6, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐄 ditto here

return fig

@staticmethod
def _find_intermediate_color(lowcolor, highcolor, intermed):
Expand Down

AltStyle によって変換されたページ (->オリジナル) /