ColormapDialog

A QDialog widget to set-up the colormap.

It uses a description of colormaps as dict compatible with Plot.

To run the following sample code, a QApplication must be initialized.

Create the colormap dialog and set the colormap description and data range:

>>> from silx.gui.dialog.ColormapDialog import ColormapDialog
>>> from silx.gui.colors import Colormap
>>> dialog = ColormapDialog()
>>> colormap = Colormap(name='red', normalization='log',
...                     vmin=1., vmax=2.)
>>> dialog.setColormap(colormap)
>>> colormap.setVRange(1., 100.)  # This scale the width of the plot area
>>> dialog.show()

Get the colormap description (compatible with Plot) from the dialog:

>>> cmap = dialog.getColormap()
>>> cmap.getName()
'red'

It is also possible to display an histogram of the image in the dialog. This updates the data range with the range of the bins.

>>> import numpy
>>> image = numpy.random.normal(size=512 * 512).reshape(512, -1)
>>> hist, bin_edges = numpy.histogram(image, bins=10)
>>> dialog.setHistogram(hist, bin_edges)

The updates of the colormap description are also available through the signal: ColormapDialog.sigColormapChanged.

class ColormapDialog(parent=None, title='Colormap Dialog')[source]

A QDialog widget to set the colormap.

Parameters:
  • parent – See QDialog
  • title (str) – The QDialog title
visibleChanged = <PySide2.QtCore.Signal object>

This event is sent when the dialog visibility change

static computeDataRange()[source]

Compute the data range as used by setDataRange().

Parameters:data – The data to process
Return type:Tuple(float, float, float)
static computeHistogram()[source]

Compute the data histogram as used by setHistogram().

Parameters:data – The data to process
Return type:Tuple(List(float),List(float)
setData(data)[source]

Store the data as a weakref.

According to the state of the dialog, the data will be used to display the data range or the histogram of the data using setDataRange() and setHistogram()

getHistogram()[source]

Returns the counts and bin edges of the displayed histogram.

Returns:(hist, bin_edges)
Return type:2-tuple of numpy arrays
setHistogram(hist=None, bin_edges=None)[source]

Set the histogram to display.

This update the data range with the bounds of the bins.

Parameters:
  • hist – array-like of counts or None to hide histogram
  • bin_edges – array-like of bins edges or None to hide histogram
getColormap()[source]

Return the colormap description.

Return type:Colormap
resetColormap()[source]

Reset the colormap state before modification.

..note :: the colormap reference state is the state when set or the
state when validated
setDataRange(minimum=None, positiveMin=None, maximum=None)[source]

Set the range of data to use for the range of the histogram area.

Parameters:
  • minimum (float) – The minimum of the data
  • positiveMin (float) – The positive minimum of the data
  • maximum (float) – The maximum of the data
storeCurrentState()[source]

save the current value sof the colormap if the user want to undo is modifications

setColormap(colormap)[source]

Set the colormap description

Parameters:colormap (Colormap) – the colormap to edit
keyPressEvent(event)[source]

Override key handling.

It disables leaving the dialog when editing a text field.