erlab.interactive.colors¶
Functions for manipulating colors in Qt.
Functions
|
Convert a matplotlib color to a |
Check if the system is in dark mode. |
|
|
Return the Matplotlib colormap name matching a display name. |
|
Get a |
|
Get all valid pyqtgraph colormap names. |
|
Apply a power-law intensity mapping to a pyqtgraph colormap. |
|
Convert a |
Classes
|
Interactive colorbar for one or more |
|
|
|
Dialog for selecting a color cycle. |
|
Colormap selector with lazy thumbnails and optional external colormaps. |
|
Slider and spinbox for adjusting colormap gamma. |
- class erlab.interactive.colors.BetterColorBarItem(parent=None, image=None, autoLevels=False, limits=None, pen='c', hoverPen='m', hoverBrush='#FFFFFF33', *, show_colormap_edit_menu=True, _defer_context_menu_setup=False, **kargs)[source]¶
Bases:
PlotItemInteractive colorbar for one or more
BetterImageItemobjects.- Parameters:
image (
Iterable[BetterImageItem] |BetterImageItem|None, default:None) – Image item or items whose colormap and intensity limits the colorbar controls.autoLevels (
bool, default:False) – Automatically update the color limits when image data changes.limits (
tuple[float,float] |None, default:None) – Fixed lower and upper bounds for the colorbar scale. If omitted, bounds are estimated from the primary image.pen (
QPen|str, default:'c') – pyqtgraph style values for the movable limit region.hoverPen (
QPen|str, default:'m') – pyqtgraph style values for the movable limit region.hoverBrush (
QBrush|str, default:'#FFFFFF33') – pyqtgraph style values for the movable limit region.show_colormap_edit_menu (
bool, default:True) – Include colormap controls in the context menu.**kargs – Additional keyword arguments passed to
pyqtgraph.PlotItem.
Notes
The colorbar keeps weak references to its image items. Changing its region updates the displayed intensity limits of all live associated images.
- property images¶
- property primary_image¶
- property colormap_properties: dict[str, Any] | None¶
Return the semantic ERLab colormap settings for the primary image.
- class erlab.interactive.colors.BetterImageItem(image=None, **kwargs)[source]¶
Bases:
ImageItempyqtgraph.ImageItemwith improved colormap support.- Parameters:
- Signals:
sigColorChanged()
sigLimitChanged(float, float)
- class erlab.interactive.colors.ColorCycleDialog(colors, *, parent=None, preview_cursors=False, opacity_values=(0.95, 0.75, 0.15, 0.35), default_colors=None)[source]¶
Bases:
QDialogDialog for selecting a color cycle.
This dialog takes a list of colors and allows the user to edit each color in the cycle, or overwrite the entire cycle by sampling from a colormap.
- Parameters:
colors (
Iterable[QColor]) – An iterable of colors to use as the initial color cycle.parent (
QWidget|None, default:None) – The parent widget for the dialog.preview_cursors (
bool, default:False) – IfTrue, the preview will include cursor lines and spans with the selected colors.opacity_values (
tuple[float,float,float,float], default:(0.95, 0.75, 0.15, 0.35)) – A tuple of four float values representing the opacity for the cursor line, cursor line hover, span background, and span edge, respectively. Each value should be between 0 and 1, where 1 is fully opaque and 0 is fully transparent.default_colors (
Iterable[QColor] |None, default:None) – An iterable of default colors to return to when the user clicks “Restore Defaults”. IfNone, the restore defaults button will not be shown.
- class erlab.interactive.colors.ColorMapComboBox(*args, **kwargs)[source]¶
Bases:
QComboBoxColormap selector with lazy thumbnails and optional external colormaps.
The initial list contains Matplotlib colormaps and is populated when the widget is first shown. The context menu can load colormaps from the optional libraries that ERLabPy detects.
- Parameters:
*args – Arguments passed to
qtpy.QtWidgets.QComboBox.**kwargs – Arguments passed to
qtpy.QtWidgets.QComboBox.
- class erlab.interactive.colors.ColorMapGammaWidget(parent=None, value=1.0, slider_cls=None, spin_cls=None)[source]¶
Bases:
QWidgetSlider and spinbox for adjusting colormap gamma.
- Signals:
valueChanged(float)
- erlab.interactive.colors.color_to_QColor(c, alpha=None)[source]¶
Convert a matplotlib color to a
PySide6.QtGui.QColor.- Parameters:
c (
tuple[float,float,float] |str|tuple[float,float,float,float] |tuple[tuple[float,float,float] |str,float] |tuple[tuple[float,float,float,float],float]) – A valid matplotlib color. See the matplotlib documentation for more information.alpha (
float|None, default:None) – If supplied, applies transparency to the color.
- Returns:
- Return type:
- erlab.interactive.colors.is_dark_mode()[source]¶
Check if the system is in dark mode.
If a QApplication is not running, this will always return False.
- erlab.interactive.colors.matplotlib_colormap_name(name)[source]¶
Return the Matplotlib colormap name matching a display name.
- erlab.interactive.colors.pg_colormap_from_name(name, skipCache=True)[source]¶
Get a
pyqtgraph.ColorMapfrom its name.- Parameters:
name (
str) – A valid colormap name.skipCache (
bool, default:True) – Whether to skip cache, by defaultTrue. Passed ontopyqtgraph.colormap.get().
- Returns:
- Return type:
- erlab.interactive.colors.pg_colormap_names(source='all', exclude_local=False)[source]¶
Get all valid pyqtgraph colormap names.
- erlab.interactive.colors.pg_colormap_powernorm(cmap, gamma, reverse=False, high_contrast=False, zero_centered=False, N=65536)[source]¶
Apply a power-law intensity mapping to a pyqtgraph colormap.
- Parameters:
cmap (
str|ColorMap) – Colormap name orpyqtgraph.ColorMap. A name is resolved withpg_colormap_from_name()without using the pyqtgraph cache. A supplied ColorMap is modified in place.gamma (
float) – Dimensionless power-law exponent. With the default contrast mode, normalized positions are mapped asx**gamma.reverse (
bool, default:False) – Reverse the colormap before the power-law mapping.high_contrast (
bool, default:False) – Use1 - (1 - x)**(1 / gamma)instead ofx**gamma.zero_centered (
bool, default:False) – Apply the mapping separately below and above the midpoint so that0.5remains fixed.N (
int, default:65536) – Number of uniformly spaced colormap positions in the returned map.
- Returns:
pyqtgraph.ColorMap– Colormap with remapped floating-point colors and positions. A supplied ColorMap is the same object after modification. The result recordsgamma,reverse,high_contrast, andzero_centeredin_erlab_attrs.- Return type:
- erlab.interactive.colors.pg_colormap_to_QPixmap(cmap, w=64, h=16, skipCache=True)[source]¶
Convert a
pyqtgraph.ColorMapto aw-by-hQPixmap thumbnail.- Parameters:
w (
int, default:64) – Specifies the dimension of the pixmap.h (
int, default:16) – Specifies the dimension of the pixmap.skipCache (
bool, optional) – Whether to skip the pyqtgraph colormap cache when resolving a string colormap, by defaultTrue. PassFalseto bypass the thumbnail cache and request the pyqtgraph-cached colormap.
- Returns:
- Return type: