from PyQt4 import QtCore, QtGui
import sys
import numpy as np
import pyqtgraph as pg
pg.setConfigOption('background', 'w'); pg.setConfigOption('foreground', 'k')
a = QtGui.QApplication([])
p = pg.PlotWidget()
line = p.plot( x = np.arange(400, 600), y = np.random.rand(200), pen = pg.mkPen('r') )
p.setXRange(0, 1000)
p.setYRange(0, 1)
p.plotItem.getAxis('left').setGrid(255)
p.plotItem.getAxis('bottom').setGrid(255)
rect = QtGui.QGraphicsRectItem( QtCore.QRectF( QtCore.QPointF(0, 0), QtCore.QSizeF(1000, 1.0) ) )
rect.setPen( pg.mkPen('b', width = 2) )
rect.setBrush( pg.mkBrush( ( 220, 220, 220 ) ) )
p.plotItem.addItem(rect)
rect.setZValue( line.zValue() - 1)
# By default, mouse-wheel zoom works in both x and y directions, but grid is hidden below rect
# When uncommenting the below lines:
# Mouse-wheel zoom works when the mouse is over the x & y axis labels, but when it is
# over the plot itself, zoom is only in the y direction
p.plotItem.getAxis('bottom').setZValue( rect.zValue() + 1 )
p.plotItem.getAxis('left').setZValue( rect.zValue() + 1 )
p.plotItem.getAxis('right').setZValue( rect.zValue() + 1 )
p.plotItem.getAxis('top').setZValue( rect.zValue() + 1 )
p.show()
sys.exit(a.exec_())