Skip to content

First Push for Trisurf Plots #453

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 29 commits into from
May 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
866ea46
First Push for Trisurf Plots
Kully May 3, 2016
273fa2b
Added tests and fixed style/organization
Kully May 5, 2016
037a89d
Updated Schema
Kully May 5, 2016
6756fc3
Replaced reduce() method because of Python 3.3 Incompatibility
Kully May 5, 2016
a47b88d
Rewrote reduce() line more explicitly and clearly for compatibility w…
Kully May 6, 2016
5226650
Try again
Kully May 6, 2016
bc42794
from functools import reduce
Kully May 6, 2016
1fe18c2
go back to reduce()
Kully May 6, 2016
781d0c8
Updated default_json
Kully May 6, 2016
463fd3e
only check layout
Kully May 6, 2016
577a900
Checks layout + data[0]
Kully May 6, 2016
d24fcef
Recopy fig data without modifying anything (i.e. PEP 8, removing extr…
Kully May 6, 2016
1daf31e
Added np. to array
Kully May 6, 2016
f7c1369
...
Kully May 6, 2016
59d8953
New expected_trisurf_plot data
Kully May 8, 2016
315723f
Again
Kully May 9, 2016
3536f6e
.....
Kully May 9, 2016
44f4c9f
Do not require initializing lists
Kully May 9, 2016
baec606
asd
Kully May 9, 2016
f77b8e6
printing both expected and test plots back to back
Kully May 9, 2016
862298d
In python 3 `map` is a generator, `list()` it!
theengineear May 10, 2016
4237742
Merge pull request #456 from plotly/fix-empty-generator-in-py3-trisurf
Kully May 10, 2016
be9112c
Removed extraneous comment//verified Pep-8 is satisfied
Kully May 10, 2016
4647830
Merge branch 'Trisurf_Plots' of https://github.com/plotly/plotly.py i…
Kully May 10, 2016
b1cb22c
Fixed up a comment
Kully May 10, 2016
8904508
Fixed Python doc strings and other formatting/naming/Pep8
Kully May 10, 2016
581f8ba
Added custom coloring option
Kully May 11, 2016
798c387
Fixed conflicts
Kully May 12, 2016
4893444
Fixed stuff
Kully May 12, 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
179 changes: 178 additions & 1 deletion plotly/tests/test_optional/test_figure_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from nose.tools import raises

import numpy as np
from scipy.spatial import Delaunay
import pandas as pd


Expand Down Expand Up @@ -532,6 +533,182 @@ def test_dendrogram_colorscale(self):
self.assert_dict_equal(dendro['data'][2], expected_dendro['data'][2])


class TestTrisurf(NumpyTestUtilsMixin, TestCase):

def test_vmin_and_vmax(self):

# check if vmin is greater than or equal to vmax
u = np.linspace(0, 2, 2)
v = np.linspace(0, 2, 2)
u, v = np.meshgrid(u, v)
u = u.flatten()
v = v.flatten()

x = u
y = v
z = u*v

points2D = np.vstack([u, v]).T
tri = Delaunay(points2D)
simplices = tri.simplices

pattern = (
"Incorrect relation between vmin and vmax. The vmin value cannot "
"be bigger than or equal to the value of vmax."
)

self.assertRaisesRegexp(PlotlyError, pattern,
tls.FigureFactory.create_trisurf,
x, y, z, simplices)

def test_valid_colormap(self):

# create data for trisurf plot
u = np.linspace(-np.pi, np.pi, 3)
v = np.linspace(-np.pi, np.pi, 3)
u, v = np.meshgrid(u, v)
u = u.flatten()
v = v.flatten()

x = u
y = u*np.cos(v)
z = u*np.sin(v)

points2D = np.vstack([u, v]).T
tri = Delaunay(points2D)
simplices = tri.simplices

# check that a valid plotly colorscale name is entered
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

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

self.assertRaisesRegexp(PlotlyError, pattern2,
tls.FigureFactory.create_trisurf,
x, y, z, simplices,
colormap=['rgb(1, 2, 3)', '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."
)

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)])

def test_trisurf_all_args(self):

# check if trisurf plot matches with expected output
u = np.linspace(-1, 1, 3)
v = np.linspace(-1, 1, 3)
u, v = np.meshgrid(u, v)
u = u.flatten()
v = v.flatten()

x = u
y = v
z = u*v

points2D = np.vstack([u, v]).T
tri = Delaunay(points2D)
simplices = tri.simplices

test_trisurf_plot = tls.FigureFactory.create_trisurf(
x, y, z, simplices
)

exp_trisurf_plot = {
'data': [
{
'facecolor': ['rgb(143.0, 123.0, 97.000000000000014)',
'rgb(255.0, 127.0, 14.000000000000007)',
'rgb(143.0, 123.0, 97.000000000000014)',
'rgb(31.0, 119.0, 180.0)',
'rgb(143.0, 123.0, 97.000000000000014)',
'rgb(31.0, 119.0, 180.0)',
'rgb(143.0, 123.0, 97.000000000000014)',
'rgb(255.0, 127.0, 14.000000000000007)'],
'i': [3, 1, 1, 5, 7, 3, 5, 7],
'j': [1, 3, 5, 1, 3, 7, 7, 5],
'k': [4, 0, 4, 2, 4, 6, 4, 8],
'name': '',
'type': 'mesh3d',
'x': np.array([-1., 0., 1., -1., 0., 1., -1., 0., 1.]),
'y': np.array([-1., -1., -1., 0., 0., 0., 1., 1., 1.]),
'z': np.array([ 1., -0., -1., -0., 0., 0., -1., 0., 1.])
},
{
'line': {'color': 'rgb(50, 50, 50)', 'width': 1.5},
'mode': 'lines',
'type': 'scatter3d',
'x': [-1.0, 0.0, 0.0, -1.0, None, 0.0, -1.0, -1.0, 0.0, None,
0.0, 1.0, 0.0, 0.0, None, 1.0, 0.0, 1.0, 1.0, None, 0.0,
-1.0, 0.0, 0.0, None, -1.0, 0.0, -1.0, -1.0, None, 1.0,
0.0, 0.0, 1.0, None, 0.0, 1.0, 1.0, 0.0, None],
'y': [0.0, -1.0, 0.0, 0.0, None, -1.0, 0.0, -1.0, -1.0, None,
-1.0, 0.0, 0.0, -1.0, None, 0.0, -1.0, -1.0, 0.0, None,
1.0, 0.0, 0.0, 1.0, None, 0.0, 1.0, 1.0, 0.0, None, 0.0,
1.0, 0.0, 0.0, None, 1.0, 0.0, 1.0, 1.0, None],
'z': [-0.0, -0.0, 0.0, -0.0, None, -0.0, -0.0, 1.0, -0.0,
None, -0.0, 0.0, 0.0, -0.0, None, 0.0, -0.0, -1.0, 0.0,
None, 0.0, -0.0, 0.0, 0.0, None, -0.0, 0.0, -1.0, -0.0,
None, 0.0, 0.0, 0.0, 0.0, None, 0.0, 0.0, 1.0, 0.0, None]
}
],
'layout': {
'height': 800,
'scene': {'aspectratio': {'x': 1, 'y': 1, 'z': 1},
'xaxis': {'backgroundcolor': 'rgb(230, 230, 230)',
'gridcolor': 'rgb(255, 255, 255)',
'showbackground': True,
'zerolinecolor': 'rgb(255, 255, 255)'},
'yaxis': {'backgroundcolor': 'rgb(230, 230, 230)',
'gridcolor': 'rgb(255, 255, 255)',
'showbackground': True,
'zerolinecolor': 'rgb(255, 255, 255)'},
'zaxis': {'backgroundcolor': 'rgb(230, 230, 230)',
'gridcolor': 'rgb(255, 255, 255)',
'showbackground': True,
'zerolinecolor': 'rgb(255, 255, 255)'}},
'title': 'Trisurf Plot',
'width': 800
}
}

self.assert_dict_equal(test_trisurf_plot['layout'],
exp_trisurf_plot['layout'])

self.assert_dict_equal(test_trisurf_plot['data'][0],
exp_trisurf_plot['data'][0])

self.assert_dict_equal(test_trisurf_plot['data'][1],
exp_trisurf_plot['data'][1])


class TestScatterPlotMatrix(NumpyTestUtilsMixin, TestCase):

def test_dataframe_input(self):
Expand Down Expand Up @@ -703,7 +880,7 @@ def test_scatter_plot_matrix(self):
columns=['Numbers', 'Fruit'])

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

Expand Down
Loading