PDA

View Full Version : PyQt4 PyQwt5 Windows 7 - Plot size problem



dayo30
21st January 2013, 00:40
I have the rudimentary beginning of a Gui for an oscilloscope.
Using 4 group boxes, with the plot in the top left box, and
3 other boxes for controls.

I can not get the plot to automatically fill the group box horizontally,
although it fits the box vertically automatically.

After searching other examples, I found #set axis scales.
Juggling the 3 lines, I can get the plot to fill the box.

Since I want to be able to select different scales, that means
that I would have to change the axis settings every time.

Also, I set MainWindow to be 800x800, but changing the axis scales,
and setAxisMajor, also changes the main window size.

Obviously, I am missing something.



self.setCanvasBackground(Qt.Qt.black)
self.plotLayout().setMargin(0)
self.plotLayout().setCanvasMargin(0)
self.plotLayout().setAlignCanvasToScales(False)

grid = Qwt.QwtPlotGrid()
grid.attach(self)
grid.setPen(Qt.QPen(Qt.Qt.white, 0, Qt.Qt.DotLine))

# set axis titles
self.setAxisTitle(Qwt.QwtPlot.xBottom, 'Time (usec)')
self.setAxisTitle(Qwt.QwtPlot.yLeft, 'Amplitude (V)')

# set axis scales
self.setAxisScale(Qwt.QwtPlot.xBottom, 0.0, 10.0)
self.setAxisScale(Qwt.QwtPlot.yLeft, -2.0, 2.0)8606
self.setAxisMaxMajor(Qwt.QwtPlot.xBottom, 25);

scaleDraw = self.axisScaleDraw(Qwt.QwtPlot.yLeft)
scaleDraw.setMinimumExtent(scaleDraw.extent(
Qt.QPen(), self.axisWidget(Qwt.QwtPlot.yLeft).font()))


Don












































after more experimentation,

Uwe
21st January 2013, 07:09
Juggling the 3 lines, I can get the plot to fill the box.
Do you mean "curve", when you say "plot", "box" might be the "canvas" and by "filling the box" you mean that the range of the x-axis should be adjusted to the bounding rectangle of the curve ?


Also, I set MainWindow to be 800x800, but changing the axis scales,
and setAxisMajor, also changes the main window size..
Do you mean the plot widget by "main window" ?

Please repeat your question using another terminology:



plot widget
canvas
curve
axis/scale


Uwe

dayo30
21st January 2013, 22:20
Do you mean "curve", when you say "plot", "box" might be the "canvas" and by "filling the box" you mean that the range of the x-axis should be adjusted to the bounding rectangle of the curve ?

Do you mean the plot widget by "main window" ?

Please repeat your question using another terminology:



plot widget
canvas
curve
axis/scale


Uwe

I have the rudimentary beginning of a Gui for an oscilloscope.
Using 4 group boxes, with the plot Widget in the top left group box, and
3 other group boxes for controls.

I can not get the canvas to automatically fill the group box horizontally,
although it fits the group box vertically automatically.

After searching other examples, I found #set axis scales.
Juggling the 3 lines, I can get the canvas to fill the box.

Since I want to be able to select different axis scales, (for instance 0 to 1 volt, or 0-5 volts, etc) that means
that I would have to change the axis settings every time.

Also, I set class MainWindow to be 800x800, by self.resize(800, 800), but changing the axis scales,
and setAxisMajor, also changes the main window size.

Also, see the jpg which , for some reason, you have to scroll down to see.

I hope that this is clearer, and thanks for helping with the terminology,
Don

Uwe
22nd January 2013, 07:58
I can not get the canvas to automatically fill the group box horizontally,
although it fits the group box vertically automatically.
The canvas is a child of the plot widget, that is a child of your group box. So when this is about, that the plot widget is not resized according to the group box the problem is unrelated to Qwt and should be a problem of your layout. Note that QwtPlot is a QWidget and for QLayoutsthere is nothing special with it compared to other widgets.


After searching other examples, I found #set axis scales.
Juggling the 3 lines, I can get the canvas to fill the box.
Sorry but this statement doesn't make more sense: the canvas is resized together with the plot widget, what is completely unrelated to the scales. The only effect on the layout you might have is, that the sizeHint() of the plot widget depends on the space that is needed for the tick labels.


Also, see the jpg which , for some reason, you have to scroll down to see.
In the screenshot I can see a plot widget that is perfectly aligned in a group box and a canvas that is perfectly aligned to its plot widget. On the canvas I can see a curve with a bounding range [ 0 - 3 ] displayed on a coordinate system with a range of [ 0 - 20 ]. This all has nothing to to do with "canvas not filling a group box".

Isn't your problem simply, that you want a coordinate system with a range according to the range of the curve ?

Uwe

dayo30
22nd January 2013, 16:25
The canvas is a child of the plot widget, that is a child of your group box. So when this is about, that the plot widget is not resized according to the group box the problem is unrelated to Qwt and should be a problem of your layout. Note that QwtPlot is a QWidget and for QLayoutsthere is nothing special with it compared to other widgets.

Sorry but this statement doesn't make more sense: the canvas is resized together with the plot widget, what is completely unrelated to the scales. The only effect on the layout you might have is, that the sizeHint() of the plot widget depends on the space that is needed for the tick labels.


In the screenshot I can see a plot widget that is perfectly aligned in a group box and a canvas that is perfectly aligned to its plot widget. On the canvas I can see a curve with a bounding range [ 0 - 3 ] displayed on a coordinate system with a range of [ 0 - 20 ]. This all has nothing to to do with "canvas not filling a group box".

Isn't your problem simply, that you want a coordinate system with a range according to the range of the curve ?

Uwe

Well, the "plot widget that is perfectly aligned in a group box and a canvas that is perfectly aligned to its plot widget" is because, as I stated earlier, I juggled the 3 "axis" statements to make it look that way. Also, as I mentioned, the canvas aligns properly, vertically, with the group box, at what ever setting of
self.setAxisScale(Qwt.QwtPlot.yLeft,.

To get the canvas to fill the group box horizontally, I had to add the line self.setAxisMaxMajor(Qwt.QwtPlot.xBottom,.
This, however, does not allow me to use whatever x axis scale that I want. There is something missing here.

I have a new screenshot, with x axis 10, and "self.setAxisMaxMajor(Qwt.QwtPlot.xBottom, 20)" commented out.
Note that the canvas does not fill the group box horizontally, and also that the when this is the case, the main
window retains its 800x800 size. Note: the combo box settings are not yet connected.

# set axis scales
self.setAxisScale(Qwt.QwtPlot.xBottom, 0.0, 10, 1)
self.setAxisScale(Qwt.QwtPlot.yLeft, -2.0, 2.0)
# self.setAxisMaxMajor(Qwt.QwtPlot.xBottom, 20)

8610

Uwe
23rd January 2013, 06:29
This issue is more or less unrelated to Qwt: read about QLayout, QWidget::sizeHint(), QWidget::sizePolicy(). Guess you are doing something wrong when inserting the plot into the layout of the group box.

The reason why you see an effect with modifying the scales is because the number of tick labels have an impact on the sizeHint() of the plot.

Uwe

dayo30
23rd January 2013, 17:25
I guess that I will have to try to understand the Qwt classes.
I have tried to use the Qwt User's Guide, but can not seem to figure them out, in relation to Py4Qwt
Is there some kind of documentation that one needs to study before it is clear?

Anyway, I thank you very much for attempting to sort this out for me.

Don

dayo30
25th January 2013, 21:35
Uwe,



The reason why you see an effect with modifying the scales is because the number of tick labels have an impact on the sizeHint() of the plot.


This was the hint that I needed!
All that I will need to do, is to have "if" statements to configure the axis scales, based on signals from the combo boxes,
to get the canvas to always be the same size.

So, on to figuring out how to do this. :-)

Thanks again for your patience,
Don