cigvis.colormap module#
Tools for colormap#
Including:
custom colormap: petrel
cmap to vispy and plotly
- cigvis.colormap.arrs_to_image(arr, cmap, clim, as_uint8=False, nancolor=None)#
- cigvis.colormap.cmap_to_mpl(cmap)#
convert vispy’s Colormap or str to matplotlib’s cmap
- cigvis.colormap.cmap_to_plotly(cmap)#
convert matplotlib’s cmap into plotly’s style
Parameters#
- cmapcmap in matplotlib
matplotlib’s cmap
Returns#
- plotly_cmapList
colormap used in plotly
- cigvis.colormap.cmap_to_vispy(cmap)#
convert matplotlib’s cmap into vispy’s style
Parameters#
- cmapcmap in matplotlib
matplotlib’s cmap
Returns#
- vispy_cmapvispy.color.Colormap
colormap used in vispy
- cigvis.colormap.custom_disc_cmap(values: List, colors: List)#
Custom a discrete colormap from values and colors. Like this:
>>> values: [v1, v2, v3, v4, v5] >>> colors: [c1, c2, c3, c4, c5] >>> bound: [v1, (v1+v2)/2, (v2+v3)/2, (v3+v4)/2, (v4+v5)/2, v5] = [b1, b2, b3, b4, b5, b6] >>> [b1, b2]: c1, [b2, b3]: c2, [b3, b4]: c3, [b4, b5]: c4, [b5, b6]: c5
Parameters#
- valuesList
values list, N elements
- colorsList
the correspanding colors of values, N elements, each elements can be str, tuple, such as ‘red’, ‘#7F0000’, (0, 0.5, 0)
Returns#
- cmapmatplotlib.colors.LinearSegmentedColormap
colormap
Examples#
>>> values = [0, 2, 7, 8] >>> colors = ['green', '#7f6580', 'blue', (0, 0.8, 0.2)] >>> cmap = custom_disc_cmap(values, colors)
- cigvis.colormap.discrete_cmap(cmap, clim, values)#
- cigvis.colormap.distinct_colors(n: int, seed: int = 0)#
Generate distinct RGBA colors for sparse line-style colormaps.
Parameters#
- nint
Number of colors.
- seedint
Random seed used to make the colors reproducible.
- cigvis.colormap.fast_set_cmap(cmap, alpha, excpt)#
fast set cmap by name, alpha and excpt, excpt could be one of [None, ‘min’, ‘max’, ‘ramp’]
- cigvis.colormap.get_cmap_from_str(cmap: str)#
return a Colormap from a cmap string
Parameters#
- cmapstr
colormap name string
- cigvis.colormap.get_colors_from_cmap(cmap, clim: List, values: List)#
get colors from a cmap when special vmin, vmax and values
Parameters#
- cmapstr or matplotlib.color.Colormap
input cmap
- climList
[vmin, vmax] to Normalize
- valuesList
list of values
Returns#
- cList
colors at norm(values) locations
- cigvis.colormap.get_custom_cmap(cmap: str) LinearSegmentedColormap#
Get a cmap from a name used in Opendtect software. The supported cmap can be see by get_opendtect_cmap_list()
- cigvis.colormap.line_cmap(cmap=None, n_lines: int = 20, samples: int = 256, seed: int = 0)#
Convert a colormap into sparse opaque lines on a transparent background.
This is useful for overlaying RGT/label-like line responses as masks. It mirrors helpers such as
set_alpha: pass a colormap object/name and get a modified matplotlibListedColormapback.Parameters#
- cmapstr or Colormap or int or None
Source colormap. If None, use reproducible distinct random colors. If an integer is passed, it is interpreted as
n_linesso calls such asline_cmap(28, 256)meann_lines=28, samples=256.- n_linesint
Number of opaque color samples.
- samplesint
Total number of samples in the returned colormap.
- seedint
Random seed used when cmap is None.
- cigvis.colormap.list_custom_cmap() List#
avaliable cmap list
- cigvis.colormap.plot_all_custom_cmap(norm: List = None, save: str = None, dpi=300)#
plot all custom cmaps with a norm
- cigvis.colormap.plot_cmap(cmap, norm: List = None, save: str = None)#
plot a cmap with a norm
Parameters#
- cmapstr or Colormap
colormap
- normList
[vmin, vmax], set value range
- savestr
name to save
- cigvis.colormap.ramp(cmap, blow=0, up=1, alpha_min=0, alpha_max=1)#
Creates a modified colormap from an existing colormap, with adjustable transparency (alpha) levels.
Parameters: - cmap: The original colormap to be modified. - blow (float, optional): The lower bound of the colormap normalization range. Defaults to 0. - up (float, optional): The upper bound of the colormap normalization range. Defaults to 1. - alpha_min (float, optional): The minimum alpha (transparency) value to apply. Defaults to 0. - alpha_max (float, optional): The maximum alpha (transparency) value to apply. Defaults to 1.
Returns: - A new colormap with alpha adjusted from alpha_min to alpha_max within the specified range [blow, up].
- cigvis.colormap.reversed(cmap)#
- cigvis.colormap.set_alpha(cmap, alpha: float)#
Set the alpha blending value, between 0 (transparent) and 1 (opaque) for a cmap. This function is mainly used in vispy which doesn’t contain a parameter like alpha in matplotlib to set opacity
Parameters#
- cmapstr or vispyColormap or mplColormap
the input cmap
- alphafloat
opacity
Returns#
cmap : str or vispyColormap or mplColormap
- cigvis.colormap.set_alpha_except_bottom(cmap, alpha, clim, segm)#
Set the alpha blending value, between 0 (transparent) and 1 (opaque) for a cmap. And set alphas in range [clim[0], segm] to 0
- cigvis.colormap.set_alpha_except_max(cmap, alpha: float)#
Set the alpha blending value, between 0 (transparent) and 1 (opaque) for a cmap and set the alpha of the max value as 0. This means mask the max value when used for a discrete show.
- cigvis.colormap.set_alpha_except_min(cmap, alpha: float)#
Set the alpha blending value, between 0 (transparent) and 1 (opaque) for a cmap and set the alpha of the min value as 0. This means mask the min value when used for a discrete show.
- cigvis.colormap.set_alpha_except_ranges(cmap, alpha, clim, r)#
Set the alpha blending value, between 0 (transparent) and 1 (opaque) for a cmap. And set the alpha of the range as 0 when clim is applied. This means mask the range of values when used for a discrete show.
Parameters#
- rList
ranges, like [0, 2] or [[1, 2], [5, 8], …]
- cigvis.colormap.set_alpha_except_top(cmap, alpha, clim, segm)#
Set the alpha blending value, between 0 (transparent) and 1 (opaque) for a cmap. And set alphas in range [segm, clim[1]] to 0
- cigvis.colormap.set_alpha_except_values(cmap, alpha: float, clim: List, values: List)#
Set the alpha blending value, between 0 (transparent) and 1 (opaque) for a cmap. And set the alpha of the select values as 0 when clim is applied. This means mask the values when used for a discrete show.
Parameters#
- cmapstr or vispyColormap or mplColormap
the input cmap
- alphafloat
opacity
- climList
[vmin, vmax] for mpl.colors.Normalize
- valuesList
the select values to except (or mask)
Returns#
cmap : str or vispyColormap or mplColormap
- cigvis.colormap.set_down_as(cmap, color)#
- cigvis.colormap.set_up_as(cmap, color)#