|
1 | 1 | from __future__ import absolute_import |
2 | | -import numpy as np |
3 | | -from scipy.interpolate import griddata |
| 2 | +from plotly import optional_imports |
4 | 3 | from plotly.graph_objs import graph_objs as go |
5 | | -import warnings |
| 4 | + |
| 5 | +import numpy as np |
| 6 | +interpolate = optional_imports.get_module('scipy.interpolate') |
6 | 7 |
|
7 | 8 |
|
8 | 9 | def _pl_deep(): |
@@ -415,8 +416,8 @@ def _compute_grid(coordinates, values, tooltip_mode): |
415 | 416 | gr_x = np.linspace(x_min, x_max, n_interp) |
416 | 417 | gr_y = np.linspace(y_min, y_max, n_interp) |
417 | 418 | grid_x, grid_y = np.meshgrid(gr_x, gr_y) |
418 | | - grid_z = griddata(cartes_coord_points[:2].T, values, (grid_x, grid_y), |
419 | | - method='cubic') |
| 419 | + grid_z = interpolate.griddata( |
| 420 | + cartes_coord_points[:2].T, values, (grid_x, grid_y), method='cubic') |
420 | 421 | bar_coords = np.einsum('ik, kmn -> imn', invM, |
421 | 422 | np.stack((grid_x, grid_y, np.ones(grid_x.shape)))) |
422 | 423 | # invalidate the points outside of the reference triangle |
@@ -495,6 +496,10 @@ def create_ternary_contour(coordinates, values, pole_labels=['a', 'b', 'c'], |
495 | 496 |
|
496 | 497 | fig = ff.create_ternary_contour(np.stack((a, b)), z, coloring='lines') |
497 | 498 | """ |
| 499 | + if interpolate is None: |
| 500 | + raise ImportError("""\ |
| 501 | +The create_ternary_contour figure factory requires the scipy package""") |
| 502 | + |
498 | 503 | grid_z, gr_x, gr_y, tooltip = _compute_grid(coordinates, values, |
499 | 504 | tooltip_mode) |
500 | 505 |
|
|
0 commit comments