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

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

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

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.

  • parent – See QDialog
  • title (str) – The QDialog title

This event is sent when the dialog visibility change

showEvent(self, QShowEvent)[source]
closeEvent(self, QCloseEvent)[source]
hideEvent(self, QHideEvent)[source]
close(self) → bool[source]
setModal(self, bool)[source]
event(self, QEvent) → bool[source]
exec(self) → int[source]
exec_(self) → int[source]
static computeDataRange(data)[source]

Compute the data range as used by setDataRange().

Parameters:data – The data to process
Return type:List[Union[None,float]]
static computeHistogram(data, scale='linear', dataRange=None)[source]

Compute the data histogram as used by setHistogram().

  • data – The data to process
  • dataRange – Optional range to compute the histogram, which is a tuple of min, max
Return type:



Store the plot item.

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


Store the data

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()

setHistogram(hist=None, bin_edges=None)[source]

Set the histogram to display.

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

  • hist – array-like of counts or None to hide histogram
  • bin_edges – array-like of bins edges or None to hide histogram

Return the colormap description.

Return type:Colormap

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.

  • minimum (float) – The minimum of the data
  • positiveMin (float) – The positive minimum of the data
  • maximum (float) – The maximum of the data

Set the range of the colormap from current item and rect.

If there is no ColormapMixIn item attached to the ColormapDialog, nothing is done.

Parameters:bounds (Union[List[float],None]) – (xmin, xmax, ymin, ymax) Rectangular region in data space

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


Set the colormap description

Parameters:colormap (Colormap) – the colormap to edit

Override key handling.

It disables leaving the dialog when editing a text field.

But several press of Return key can be use to validate and close the dialog.