Skip to content

Fix for figure factory import when scipy not installed #1423

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 3 commits into from
Feb 4, 2019
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
6 changes: 5 additions & 1 deletion plotly/figure_factory/__init__.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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