Skip to content

Plus 2 colorscale #477

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 6 commits into from
May 27, 2016
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
116 changes: 79 additions & 37 deletions plotly/tests/test_optional/test_figure_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,18 +627,6 @@ def test_valid_colormap(self):
self.assertRaises(PlotlyError, tls.FigureFactory.create_trisurf,
x, y, z, simplices, colormap='foo')

# check that colormap is a list, if not a string

pattern1 = (
"If 'colormap' is a list, then its items must be tripets of the "
"form a,b,c or 'rgbx,y,z' where a,b,c are between 0 and 1 "
"inclusive and x,y,z are between 0 and 255 inclusive."
)

self.assertRaisesRegexp(PlotlyError, pattern1,
tls.FigureFactory.create_trisurf,
x, y, z, simplices, colormap=3)

# check: if colormap is a list of rgb color strings, make sure the
# entries of each color are no greater than 255.0

Expand All @@ -650,20 +638,31 @@ def test_valid_colormap(self):
self.assertRaisesRegexp(PlotlyError, pattern2,
tls.FigureFactory.create_trisurf,
x, y, z, simplices,
colormap=['rgb(1, 2, 3)', 'rgb(4, 5, 600)'])
colormap=['rgb(4, 5, 600)'])

# check: if colormap is a list of tuple colors, make sure the entries
# of each tuple are no greater than 1.0

pattern3 = (
"Whoops! The elements in your rgb colormap tuples "
"cannot exceed 1.0."
"Whoops! The elements in your colormap tuples cannot exceed 1.0."
)

self.assertRaisesRegexp(PlotlyError, pattern3,
tls.FigureFactory.create_trisurf,
x, y, z, simplices,
colormap=[(0.2, 0.4, 0.6), (0.8, 1.0, 1.2)])
colormap=[(0.8, 1.0, 1.2)])

# check:

pattern4 = (
"You must input a valid colormap. Valid types include a plotly "
"scale, rgb, hex or tuple color, or lastly a list of any color "
"types."
)

self.assertRaisesRegexp(PlotlyError, pattern4,
tls.FigureFactory.create_trisurf,
x, y, z, simplices, colormap=1)

def test_trisurf_all_args(self):

Expand Down Expand Up @@ -865,27 +864,55 @@ def test_same_data_in_index(self):
tls.FigureFactory.create_scatterplotmatrix,
df, index='apple')

def test_valid_palette(self):
def test_valid_colormap(self):

# check: the palette argument is in a acceptable form
# check: the colormap argument is in a valid form
df = pd.DataFrame([[1, 2, 3], [4, 5, 6], [7, 8, 9]],
columns=['a', 'b', 'c'])

self.assertRaisesRegexp(PlotlyError, "You must pick a valid "
"plotly colorscale name.",
tls.FigureFactory.create_scatterplotmatrix,
df, use_theme=True, index='a',
palette='fake_scale')
# check: valid plotly scalename is entered
self.assertRaises(PlotlyError,
tls.FigureFactory.create_scatterplotmatrix,
df, index='a', colormap='fake_scale')

pattern = (
"The items of 'palette' must be tripets of the form a,b,c or "
"'rgbx,y,z' where a,b,c belong to the interval 0,1 and x,y,z "
"belong to 0,255."
"You must input a valid colormap. Valid types include a plotly "
"scale, rgb, hex or tuple color, a list of any color types, or a "
"dictionary with index names each assigned to a color."
)

# check: accepted data type for colormap
self.assertRaisesRegexp(PlotlyError, pattern,
tls.FigureFactory.create_scatterplotmatrix,
df, use_theme=True, palette=1, index='c')
df, colormap=1)

pattern_rgb = (
"Whoops! The elements in your rgb colormap tuples cannot "
"exceed 255.0."
)

# check: proper 'rgb' color
self.assertRaisesRegexp(PlotlyError, pattern_rgb,
tls.FigureFactory.create_scatterplotmatrix,
df, colormap='rgb(500, 1, 1)', index='c')

self.assertRaisesRegexp(PlotlyError, pattern_rgb,
tls.FigureFactory.create_scatterplotmatrix,
df, colormap=['rgb(500, 1, 1)'], index='c')

pattern_tuple = (
"Whoops! The elements in your colormap tuples cannot "
"exceed 1.0."
)

# check: proper color tuple
self.assertRaisesRegexp(PlotlyError, pattern_tuple,
tls.FigureFactory.create_scatterplotmatrix,
df, colormap=(2, 1, 1), index='c')

self.assertRaisesRegexp(PlotlyError, pattern_tuple,
tls.FigureFactory.create_scatterplotmatrix,
df, colormap=[(2, 1, 1)], index='c')

def test_valid_endpts(self):

Expand All @@ -900,20 +927,35 @@ def test_valid_endpts(self):

self.assertRaisesRegexp(PlotlyError, pattern,
tls.FigureFactory.create_scatterplotmatrix,
df, use_theme=True, index='a',
palette='Blues', endpts='foo')
df, index='a', colormap='Hot', endpts='foo')

# check: the endpts are a list of numbers
self.assertRaisesRegexp(PlotlyError, pattern,
tls.FigureFactory.create_scatterplotmatrix,
df, use_theme=True, index='a',
palette='Blues', endpts=['a'])
df, index='a', colormap='Hot', endpts=['a'])

# check: endpts is a list of INCREASING numbers
self.assertRaisesRegexp(PlotlyError, pattern,
tls.FigureFactory.create_scatterplotmatrix,
df, use_theme=True, index='a',
palette='Blues', endpts=[2, 1])
df, index='a', colormap='Hot', endpts=[2, 1])

def test_dictionary_colormap(self):

# if colormap is a dictionary, make sure it all the values in the
# index column are keys in colormap
df = pd.DataFrame([['apple', 'happy'], ['pear', 'sad']],
columns=['Fruit', 'Emotion'])

colormap = {'happy': 'rgb(5, 5, 5)'}

pattern = (
"If colormap is a dictionary, all the names in the index "
"must be keys."
)

self.assertRaisesRegexp(PlotlyError, pattern,
tls.FigureFactory.create_scatterplotmatrix,
df, index='Emotion', colormap=colormap)

def test_scatter_plot_matrix(self):

Expand All @@ -926,7 +968,7 @@ def test_scatter_plot_matrix(self):

test_scatter_plot_matrix = tls.FigureFactory.create_scatterplotmatrix(
df=df, diag='scatter', height=1000, width=1000, size=13,
title='Scatterplot Matrix', use_theme=False
title='Scatterplot Matrix'
)

exp_scatter_plot_matrix = {
Expand Down Expand Up @@ -1020,17 +1062,17 @@ def test_scatter_plot_matrix_kwargs(self):
test_scatter_plot_matrix = tls.FigureFactory.create_scatterplotmatrix(
df, index='Fruit', endpts=[-10, -1], diag='histogram',
height=1000, width=1000, size=13, title='Scatterplot Matrix',
use_theme=True, palette='YlOrRd', marker=dict(symbol=136)
colormap='YlOrRd', marker=dict(symbol=136)
)

exp_scatter_plot_matrix = {
'data': [{'marker': {'color': 'rgb(128.0, 0.0, 38.0)'},
'data': [{'marker': {'color': 'rgb(128,0,38)'},
'showlegend': False,
'type': 'histogram',
'x': [2, -15, -2, 0],
'xaxis': 'x1',
'yaxis': 'y1'},
{'marker': {'color': 'rgb(255.0, 255.0, 204.0)'},
{'marker': {'color': 'rgb(255,255,204)'},
'showlegend': False,
'type': 'histogram',
'x': [6, 5],
Expand Down
Loading