def add_plot_image_histogram(widget, image_data, show_plot_axes=False,
add_scale_buttons=False):
"""
Add a PlotItem, attached ImageItem, and HistogramLUTWidget to a QWidget.
(e.g. created in QTDesigner)
The image is offset such that integer plot coordinates correspond
to pixel centers rather than corners (which is the default).
widget: a QWidget
image_data: initial image data
show_plot_axes: if False, hide all the plot axes. If True, show
the default ('left' & 'bottom' are shown).
add_scale_buttons: if True, add up- and down-triangle buttons to
increase and decrease image color map limits and
a square button for resetting them (see ImageItemUpdater).
returns None
"""
layout = QtGui.QGridLayout()
widget.setLayout(layout)
layout.setSpacing(0)
widget.plotView = pg.GraphicsView()
layout.addWidget(widget.plotView, 0, 0, 3, 1)
widget.plotItem = pg.PlotItem()
widget.plotItem.setAspectLocked()
widget.plotItem.resize = widget.resize
if not show_plot_axes:
for axis in ('left','bottom','top','right'):
widget.plotItem.showAxis(axis, False)
widget.plotView.setCentralItem(widget.plotItem)
widget.imageItem = pg.ImageItem(image=image_data)
# to make plotted points _centered_ on corresponding image pixels
widget.imageItem.translate(-.5,-.5)
# put image _behind_ plot
widget.imageItem.setZValue(-100)
if add_scale_buttons:
button_radius = 12 # pixels
image_height = widget.imageItem.height()
# 'up' button in upper-left corner
widget.up_button = Button(button_radius, typ='tu', \
parent=widget.imageItem)
widget.up_button.setPos(0, 0.95*image_height)
# 'down' button just below it
widget.down_button = Button(button_radius, typ='td', \
parent=widget.imageItem)
widget.down_button.setPos(0, 0.80*image_height)
# 'reset' (square) button in lower-left corner
widget.reset_button = Button(button_radius, typ='s',
parent=widget.imageItem)
widget.plotItem.addItem(widget.imageItem)
widget.histogramView = pg.GraphicsView()