MCPcopy
hub / github.com/tum-pbs/PhiFlow / plot

Method plot

phi/vis/_matplotlib/_matplotlib_plots.py:328–357  ·  view source on GitHub ↗
(self, data: Field, figure, subplot, space: Box, min_val: float, max_val: float, show_color_bar: bool, color: Tensor, alpha: Tensor, err: Tensor)

Source from the content-addressed store, hash-verified

326 return data.is_grid and channel(data).volume == 1 and data.spatial_rank == 2 and not instance(data) and math.is_finite(data.values).any
327
328 def plot(self, data: Field, figure, subplot, space: Box, min_val: float, max_val: float, show_color_bar: bool, color: Tensor, alpha: Tensor, err: Tensor):
329 dims = spatial(data)
330 vector = data.geometry.shape['vector']
331 bounds = data.geometry.bounds
332 if bounds.upper.vector.item_names is not None:
333 left, bottom = bounds.lower.vector[dims]
334 right, top = bounds.upper.vector[dims]
335 else:
336 dim_indices = data.resolution.indices(dims)
337 left, bottom = bounds.lower.vector[dim_indices]
338 right, top = bounds.upper.vector[dim_indices]
339 extent = (float(left), float(right), float(bottom), float(top))
340 if space.spatial_rank == 3: # surface plot
341 z = data.values.numpy(dims)
342 x, y = reshaped_numpy(data.points, [vector, *spatial(data)])
343 plot_surface(subplot, x, y, z)
344 else: # heatmap
345 aspect = subplot.get_aspect()
346 image = data.values.numpy(dims.reversed)
347 if data.values.dtype.kind == complex:
348 amplitude = abs(image) / np.max(abs(image))
349 phase = np.angle(image) / (2*np.pi) + .5
350 hsv = np.stack([phase, np.ones_like(amplitude), amplitude], -1)
351 rgb = matplotlib.colors.hsv_to_rgb(hsv)
352 subplot.imshow(rgb, origin='lower', extent=extent, vmin=min_val, vmax=max_val, aspect=aspect, alpha=float(alpha))
353 else:
354 subplot.imshow(image, origin='lower', extent=extent, vmin=min_val, vmax=max_val, aspect=aspect, alpha=float(alpha))
355 if show_color_bar:
356 add_color_bar(subplot, data.values.numpy(dims), min_val, max_val)
357 return True
358
359
360class VectorField2D(Recipe):

Callers

nothing calls this directly

Calls 4

plot_surfaceFunction · 0.85
add_color_barFunction · 0.85
numpyMethod · 0.80
stackMethod · 0.80

Tested by

no test coverage detected