diff --git a/plotly/figure_factory/__init__.py b/plotly/figure_factory/__init__.py index b7dd72c21bd..04937a44973 100644 --- a/plotly/figure_factory/__init__.py +++ b/plotly/figure_factory/__init__.py @@ -3,7 +3,11 @@ from plotly import optional_imports # Require that numpy exists for figure_factory -import numpy +np = optional_imports.get_module('numpy') +if np is None: + raise ImportError("""\ +The figure factory module requires the numpy package""") + from plotly.figure_factory._2d_density import create_2d_density from plotly.figure_factory._annotated_heatmap import create_annotated_heatmap diff --git a/plotly/figure_factory/_ternary_contour.py b/plotly/figure_factory/_ternary_contour.py index 6a8079c9224..d74254f2854 100644 --- a/plotly/figure_factory/_ternary_contour.py +++ b/plotly/figure_factory/_ternary_contour.py @@ -1,8 +1,9 @@ from __future__ import absolute_import -import numpy as np -from scipy.interpolate import griddata +from plotly import optional_imports from plotly.graph_objs import graph_objs as go -import warnings + +import numpy as np +interpolate = optional_imports.get_module('scipy.interpolate') def _pl_deep(): @@ -415,8 +416,8 @@ def _compute_grid(coordinates, values, tooltip_mode): gr_x = np.linspace(x_min, x_max, n_interp) gr_y = np.linspace(y_min, y_max, n_interp) grid_x, grid_y = np.meshgrid(gr_x, gr_y) - grid_z = griddata(cartes_coord_points[:2].T, values, (grid_x, grid_y), - method='cubic') + grid_z = interpolate.griddata( + cartes_coord_points[:2].T, values, (grid_x, grid_y), method='cubic') bar_coords = np.einsum('ik, kmn -> imn', invM, np.stack((grid_x, grid_y, np.ones(grid_x.shape)))) # invalidate the points outside of the reference triangle @@ -495,6 +496,10 @@ def create_ternary_contour(coordinates, values, pole_labels=['a', 'b', 'c'], fig = ff.create_ternary_contour(np.stack((a, b)), z, coloring='lines') """ + if interpolate is None: + raise ImportError("""\ +The create_ternary_contour figure factory requires the scipy package""") + grid_z, gr_x, gr_y, tooltip = _compute_grid(coordinates, values, tooltip_mode)