Hi,
Does this behave better? Using setLimits(), since setXRange() etc is just a
once-off change to the view bounds.
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
app = pg.mkQApp("Range Example")
glw = pg.GraphicsLayoutWidget(show=True, title="GLW title")
#glw.setBackground('w')
glw.setWindowTitle('pyqtgraph example: Plotting')
plt = glw.addPlot(title='plot title')
_width = 2000
_height = 6000
glw.resize(_width/3, _height/3)
plt.setLimits(xMin=0, xMax=_width, yMin=0, yMax=_height)
plt.setXRange(0, _width, padding=0)
plt.setYRange(0, _height, padding=0)
plt.setAspectLocked(lock=True, ratio=1)
plt.plot([_width/4, _width/2, _width/2, _width/4, _width/4], [_width/4,
_width/4, _width/2, _width/2, _width/4])
if __name__ == '__main__':
pg.mkQApp().exec_()
Patrick
On Tuesday, 24 August 2021 at 6:25:45 am UTC+9:30 James wrote:
> Hi,
>
> I'd like to force the x-range and y-range to specific values meaning that
> the plot axes should start and stop at those limits (no padding). I also
> want to specify a fixed aspect ratio of 1:1 (so that dx=100 takes the same
> screen space as dy=100, i.e. a square will display with equal number of
> pixels in length and width).
>
> When I try the following, the displayed x-axis extends beyond the
> specified limits. Do I need to force the ViewBox to have a specific size
> that is consistent with the fixed aspect ratio and x/y ranges?
>
> from pyqtgraph.Qt import QtGui, QtCore
> import pyqtgraph as pg
>
> app = pg.mkQApp("Range Example")
>
> glw = pg.GraphicsLayoutWidget(show=True, title="GLW title")
> glw.setBackground('w')
> glw.setWindowTitle('pyqtgraph example: Plotting')
>
> plt = glw.addPlot(title='plot title')
>
> _width = 2000
> _height = 6000
> glw.resize(_width/3, _height/3)
> plt.setXRange(0, _width, padding=0)
> plt.setYRange(0, _height, padding=0)
> plt.setAspectLocked(lock=True, ratio=1)
>
> if __name__ == '__main__':
> pg.mkQApp().exec_()
>
>
>
>
>
>
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/78db5af6-0e24-4e7b-b7f8-aacb85db5f88n%40googlegroups.com.