Skip to content

Commit

Permalink
[WIP] fix for figure factory import when scipy not installed (#1423)
Browse files Browse the repository at this point in the history
Fix for figure factory import when scipy not installed
  • Loading branch information
jonmmease committed Feb 4, 2019
1 parent 5a41c59 commit 385854d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
6 changes: 5 additions & 1 deletion plotly/figure_factory/__init__.py
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions 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():
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 385854d

Please sign in to comment.