I need to display some curves on monitor in their natural size and proportions. All the curves are given in their "real world" coordinates expressed in millimeters. I guess this is called "scale coordinate system" in Qwt. The best size of their bounding box seems to be 249 x 92 mm since it can be mapped pretty precise to 925 x 342 pixels (0.2692 mm/pixel pitch). I would also like to have QwtPlot widget (or its canvas, right?) have this size in the MainForm before any curves are attached to it.
Following sketch of my very naive code:
self.Plt.move(10,25)
self.
Plt.
setAxisScale(Qwt.
QwtPlot.
yLeft,
-46.0,
46.0)self.
Plt.
setAxisScale(Qwt.
QwtPlot.
xBottom,
-124.5,
124.5,
20) self.Plt.canvas().resize(925,342)
rescaler = Qwt.QwtPlotRescaler(self.Plt.canvas())
self.Plt.updateAxes()
self.Plt.plotLayout().setAlignCanvasToScales(True)
self.Plt = Qwt.QwtPlot(self)
self.Plt.move(10,25)
self.Plt.setAxisScale(Qwt.QwtPlot.yLeft, -46.0, 46.0)
self.Plt.setAxisScale(Qwt.QwtPlot.xBottom, -124.5, 124.5,20)
self.Plt.canvas().resize(925,342)
rescaler = Qwt.QwtPlotRescaler(self.Plt.canvas())
self.Plt.updateAxes()
self.Plt.plotLayout().setAlignCanvasToScales(True)
To copy to clipboard, switch view to plain text mode
gives me attached output:QwtPlot.png
Obviously this widget has neither 925 nor 342 pixels in width/height and the Y axis is truncated. "White only" area (canvas?) is 477 x 162 pixels. Following calls give pretty unexpected values as well:
self.Plt.plotLayout().canvasRect()
self.Plt.canvas().contentsRect()
self.Plt.geometry()
self.Plt.canvas().height()
self.Plt.canvas().width()
self.Plt.plotLayout().scaleRect(0)
self.Plt.plotLayout().canvasRect()
self.Plt.canvas().contentsRect()
self.Plt.geometry()
self.Plt.canvas().height()
self.Plt.canvas().width()
self.Plt.plotLayout().scaleRect(0)
To copy to clipboard, switch view to plain text mode
canvasRect
: PyQt4.
QtCore.
QRect(11,
52,
89,
-33)contentsRect
: PyQt4.
QtCore.
QRect(2,
2,
85,
-4)geometry
: PyQt4.
QtCore.
QRect(10,
25,
100,
30)canvas height: 0
canvas widht: 89
scaleRect
: PyQt4.
QtCore.
QRect(0,
24,
11,
6)
canvasRect: PyQt4.QtCore.QRect(11, 52, 89, -33)
contentsRect: PyQt4.QtCore.QRect(2, 2, 85, -4)
geometry: PyQt4.QtCore.QRect(10, 25, 100, 30)
canvas height: 0
canvas widht: 89
scaleRect: PyQt4.QtCore.QRect(0, 24, 11, 6)
To copy to clipboard, switch view to plain text mode
The only understandable values are 10, 25.
After adding some curves (stright lines in real world) which are forming a rectangular with edges in (-119,37),(119,37),(119,-37),(-119,-37) in the "real world" millimeters and calling
b=self.curve.boundingRect()
print b, ' ', b.top(), ' ', b.bottom(), ' ', b.left(),' ',b.right()
b=self.curve.boundingRect()
print b, ' ', b.top(), ' ', b.bottom(), ' ', b.left(),' ',b.right()
To copy to clipboard, switch view to plain text mode
in the output
PyQt4.
QtCore.
QRectF(119.0,
-37.0,
0.0,
74.0) -37.0 37.0 119.0 119.0
PyQt4.QtCore.QRectF(119.0, -37.0, 0.0, 74.0) -37.0 37.0 119.0 119.0
To copy to clipboard, switch view to plain text mode
the origin of 74.0 seems to be not quite clear as well.
I'm pretty much lost here... Probably I need to establish some mapping (QwtScaleMap?) and only then setAxisScale, with created rescaler (QwtPlotRescaler ?).
Could anyone show some rough code sketch/hint, please ?
Bookmarks