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

Method plot

phi/vis/_matplotlib/_matplotlib_plots.py:493–520  ·  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

491 return data.spatial_rank == 2 and 'vector' in channel(data) and data.is_grid and (data.values != 0).any and all(dim.size > 1 for dim in data.resolution)
492
493 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):
494 vector = data.geometry.shape['vector']
495 data = data.at_centers()
496 with math.precision(64): # streamplot requires very precise grid spacing
497 x, y = reshaped_numpy(data.points, [vector, *data.shape.without('vector')])
498 x = x[:, 0]
499 y = y[0, :]
500 u, v = reshaped_numpy(data.values.vector[vector.item_names[0]], [vector, *data.shape.without('vector')])
501 if wrap(color == 'cmap').all:
502 col = reshaped_numpy(math.vec_length(data.values), [*data.shape.without('vector')]).T
503 elif color.shape:
504 col = [_plt_col(c) for c in color.numpy(data.shape.non_channel).reshape(-1)]
505 else:
506 col = _plt_col(color)
507 alphas = reshaped_numpy(alpha, [data.shape.without('vector')])
508 a = float(alphas[0])
509 prev_patches = set(subplot.patches)
510 try:
511 stream = subplot.streamplot(x, y, u.T, v.T, color=col, cmap=colormaps.get_cmap(matplotlib.rcParams['image.cmap']))
512 except ValueError as err: # no lines cause
513 if err.args[0] == "need at least one array to concatenate":
514 return
515 raise err
516 stream.lines.set_alpha(a)
517 new_patches = set(subplot.patches) - prev_patches
518 for obj in new_patches:
519 # if isinstance(obj, matplotlib.patches.FancyArrowPatch):
520 obj.set_alpha(a)
521
522
523class EmbeddedPoint2D(Recipe):

Callers

nothing calls this directly

Calls 4

_plt_colFunction · 0.85
at_centersMethod · 0.80
withoutMethod · 0.80
numpyMethod · 0.80

Tested by

no test coverage detected