Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _add_colorbar(ren, lut, location):
orientation = 'horizontal'
if location in ['left', 'right']:
orientation = 'vertical'
text_pos = 'succeedScalarBar'
if location in ['left', 'bottom']:
text_pos = 'precedeScalarBar'
kwbs = dp.scalarBarActor_kwds.copy()
kwbs.update({'lookuptable': lut, 'orientation': orientation,
'textPosition': text_pos})
return ren.AddScalarBarActor(**kwbs)
actor = dp.actor_kwds.copy()
actor.update({k: v[i, j][ia] for k, v in actor_kwds.items()})
if view[i, j] is not None:
actor['orientation'] = orientations[view[i, j]]
# Mapper
mapper = dp.mapper_kwds.copy()
mapper['scalarVisibility'] = name is not True
mapper['interpolateScalarsBeforeMapping'] = not sp['disc']
mapper.update({k: v[i, j][ia] for k, v in mapper_kwds.items()})
mapper['inputDataObject'] = s
if name is not True:
mapper['arrayName'] = name
# Lut
lut = dp.lookuptable_kwds.copy()
lut['numberOfTableValues'] = sp['nval']
lut['range'] = (sp['min'], sp['max'])
cm = cmap[i, j][ia]
if cm is not None:
if cm in colormaps:
table = colormaps[cm]
else:
cm = plt.get_cmap(cm)
nvals = lut['numberOfTableValues']
table = cm(np.linspace(0, 1, nvals)) * 255
table = table.astype(np.uint8)
lut['table'] = table
if nan_color:
lut['nanColor'] = nan_color
def _add_text(ren, text, location):
orientation = 0
if location == 'left':
orientation = 90
elif location == 'right':
orientation = -90
kwds = dp.textActor_kwds.copy()
kwds.update({'input': text, 'orientation': orientation})
return ren.AddTextActor(**kwds)
if sp['disc']:
lut['IndexedLookup'] = True
color_idx = sp['val']
lut['annotations'] = (color_idx, color_idx.astype(str))
mapper['lookuptable'] = lut
ren.AddActor(**actor, mapper=mapper)
ren.ResetCamera()
ren.activeCamera.parallelProjection = True
ren.activeCamera.Zoom(zoom[i, j])
# Plot renderers for color bar, text
for e in entries:
kwds = dp.renderer_kwds.copy()
kwds.update({'row': e.row, 'col': e.col, 'background': background})
ren1 = p.AddRenderer(**kwds)
if isinstance(e.label, str):
_add_text(ren1, e.label, e.loc)
else: # color bar
ren_lut = p.renderers[p.populated[e.label]][-1]
lut = ren_lut.actors.lastActor.mapper.lookupTable
_add_colorbar(ren1, lut.VTKObject, e.loc)
return p
kwds.update({k: v[i, j] for k, v in ren_kwds.items()})
kwds['background'] = background # just in case
ren = p.AddRenderer(**kwds)
if layout[i, j] is None:
continue
s = surfs[layout[i, j]]
for ia, name in enumerate(array_name[i, j]):
if name is False or name is None:
continue
sp = specs[ia, i, j]
# Actor
actor = dp.actor_kwds.copy()
actor.update({k: v[i, j][ia] for k, v in actor_kwds.items()})
if view[i, j] is not None:
actor['orientation'] = orientations[view[i, j]]
# Mapper
mapper = dp.mapper_kwds.copy()
mapper['scalarVisibility'] = name is not True
mapper['interpolateScalarsBeforeMapping'] = not sp['disc']
mapper.update({k: v[i, j][ia] for k, v in mapper_kwds.items()})
mapper['inputDataObject'] = s
if name is not True:
mapper['arrayName'] = name
# Lut
lut = dp.lookuptable_kwds.copy()
lut['numberOfTableValues'] = sp['nval']
s = surfs[layout[i, j]]
for ia, name in enumerate(array_name[i, j]):
if name is False or name is None:
continue
sp = specs[ia, i, j]
# Actor
actor = dp.actor_kwds.copy()
actor.update({k: v[i, j][ia] for k, v in actor_kwds.items()})
if view[i, j] is not None:
actor['orientation'] = orientations[view[i, j]]
# Mapper
mapper = dp.mapper_kwds.copy()
mapper['scalarVisibility'] = name is not True
mapper['interpolateScalarsBeforeMapping'] = not sp['disc']
mapper.update({k: v[i, j][ia] for k, v in mapper_kwds.items()})
mapper['inputDataObject'] = s
if name is not True:
mapper['arrayName'] = name
# Lut
lut = dp.lookuptable_kwds.copy()
lut['numberOfTableValues'] = sp['nval']
lut['range'] = (sp['min'], sp['max'])
cm = cmap[i, j][ia]
if cm is not None:
if cm in colormaps:
table = colormaps[cm]
label_text = {'left': label_text}
# Array ranges
specs = _get_ranges(layout, surfs, array_name, share, color_range)
# Grid
grid_row, grid_col, ridx, cidx, entries = \
_gen_grid(nrow, ncol, label_text, color_bar, share)
kwargs.update({'nrow': grid_row, 'ncol': grid_col, 'size': size})
p = Plotter(**kwargs)
for iren, jren in iter_prod(range(len(ridx)), range(len(cidx))):
i, j = ridx[iren], cidx[jren]
kwds = dp.renderer_kwds.copy()
kwds.update({'row': iren, 'col': jren, 'background': background})
# Renderers for empty entries
if isinstance(i, str) or isinstance(j, str):
if isinstance(i, str) and isinstance(j, str):
p.AddRenderer(**kwds)
continue
kwds.update({k: v[i, j] for k, v in ren_kwds.items()})
kwds['background'] = background # just in case
ren = p.AddRenderer(**kwds)
if layout[i, j] is None:
continue
s = surfs[layout[i, j]]