MCPcopy Index your code
hub / github.com/plotly/plotly.py / _compute_grid

Function _compute_grid

plotly/figure_factory/_ternary_contour.py:187–222  ·  view source on GitHub ↗

Transform data points with Cartesian or ILR mapping, then Compute interpolation on a regular grid. Parameters ========== coordinates : array-like Barycentric coordinates of data points. values : 1-d array-like Data points, field to be represented as contour

(coordinates, values, interp_mode="ilr")

Source from the content-addressed store, hash-verified

185
186
187def _compute_grid(coordinates, values, interp_mode="ilr"):
188 """
189 Transform data points with Cartesian or ILR mapping, then Compute
190 interpolation on a regular grid.
191
192 Parameters
193 ==========
194
195 coordinates : array-like
196 Barycentric coordinates of data points.
197 values : 1-d array-like
198 Data points, field to be represented as contours.
199 interp_mode : 'ilr' (default) or 'cartesian'
200 Defines how data are interpolated to compute contours.
201 """
202 if interp_mode == "cartesian":
203 M, invM = _transform_barycentric_cartesian()
204 coord_points = np.einsum("ik, kj -> ij", M, coordinates)
205 elif interp_mode == "ilr":
206 coordinates = _replace_zero_coords(coordinates)
207 coord_points = _ilr_transform(coordinates)
208 else:
209 raise ValueError("interp_mode should be cartesian or ilr")
210 xx, yy = coord_points[:2]
211 x_min, x_max = xx.min(), xx.max()
212 y_min, y_max = yy.min(), yy.max()
213 n_interp = max(200, int(np.sqrt(len(values))))
214 gr_x = np.linspace(x_min, x_max, n_interp)
215 gr_y = np.linspace(y_min, y_max, n_interp)
216 grid_x, grid_y = np.meshgrid(gr_x, gr_y)
217 # We use cubic interpolation, except outside of the convex hull
218 # of data points where we use nearest neighbor values.
219 grid_z = scipy_interp.griddata(
220 coord_points[:2].T, values, (grid_x, grid_y), method="cubic"
221 )
222 return grid_z, gr_x, gr_y
223
224
225# ----------------------- Contour traces ----------------------

Callers 1

create_ternary_contourFunction · 0.85

Calls 5

_replace_zero_coordsFunction · 0.85
_ilr_transformFunction · 0.85
intFunction · 0.85
minMethod · 0.45

Tested by

no test coverage detected