Thanks for the suggestion Patrick. This does work for me in the minimal working example above, as long as the glw.resize() sets the aspect ratio of the GraphicsLayoutWidget to match that of the desired plot (and the GLW fits on my screen). But when I try this in a GUI, I have a problem. See e.g. the following MWE in which I have a PlotWidget and a QPushButton in a QHBoxLayout().
Without resizing the PlotWidget, the axis limits are not respected (should be x=[0,2000], y=[0,6000]). And calling resize on the PlotWidget seems to have no effect on the displayed size of the PW (see code below and attached image).
So it looks like the plot axes are forced to fill the entire PlotWidget area (or at least they do by default), which makes it hard to enforce an aspect ratio for the axes that doesn't match the aspect ratio of the PlotWidget itself.
There must be a way to do this (e.g. in matplotlib I can configure a set of axes to have whatever aspect ratio I'd like, independent of the dimensions of the figure that holds those axes -- see code below and attached image).
# pyqtgraph version
import sys
import PyQt5.QtWidgets as qtw
import pyqtgraph as pg
app = qtw.QApplication(sys.argv)
window = qtw.QWidget()
window.setWindowTitle('Fixed aspect ratio')
layout = qtw.QHBoxLayout()
layout.addWidget(qtw.QPushButton('Button'))
_width = 2000
_height = 6000
pw = pg.PlotWidget()
pw.setLimits(xMin=0, xMax=_width, yMin=0, yMax=_height)
pw.setRange(xRange=(0, _width), yRange=(0, _height), padding=0, update=True, disableAutoRange=True)
pw.resize(_width, _height)
pw.setAspectLocked(lock=True, ratio=1)
pw.setMouseEnabled(x=False, y=False)
layout.addWidget(pw)
window.setLayout(layout)
window.show()
# Plot a square
pw.plot([_width/4, _width/2, _width/2, _width/4, _width/4], [_width/4, _width/4, _width/2, _width/2, _width/4])
sys.exit(app.exec_())
# Matplotlib version
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(15,5)) # aspect ratio 3:1
ax1 = fig.add_subplot(1,1,1, adjustable='box', aspect=1)
ax1.plot(range(10)) # axes are 1:1 within the 3:1 figure
plt.show()