PlotPyStack / PythonQwt

Qt plotting widgets for Python (pure Python reimplementation of Qwt C++ library)
https://pypi.org/project/PythonQwt/
Other
86 stars 25 forks source link

Add support for geometry based axis auto-scaling #39

Open estan opened 8 years ago

estan commented 8 years ago

I'm currently using auto-scaling for my X-axis, but I noticed that I'm still prevented from making the plot smaller beyond a certain point. It would be great if the axis auto-scaling feature could work such that the axis division is recalculated based on the new size when the geometry of the widget changed, not just when replotupdateAxes is called. This would allow a dynamic behavior where the division of the axis scale is coarser when the plot is narrow, and finer when it is wide.

PierreRaybaut commented 8 years ago

Do you mean that adding the following code to your QwtPlot derived class would do the trick?

class MyPlot(QwtPlot):
    def resizeEvent(self, event):
        QwtPlot.resizeEvent(self, event)
        self.replot()
estan commented 8 years ago

Ah. Hm, I'm not sure, I'll give it a try, but I'm doubtful. The call to QwtPlot.resizeEvent(..) would be the same as what I'm getting now (it wouldn't resize smaller the plot smaller than what is currently possible), so the replot() would just be a (visual) no-op, or?

estan commented 8 years ago

I made the following test:

from os import environ
from sys import argv, exit

from numpy import linspace, sin, pi
from PyQt5.QtWidgets import QApplication, QMainWindow

environ['QT_API'] = 'pyqt5'

from qwt import QwtPlot, QwtPlotCurve

class TestPlot1(QwtPlot):
    """Without resizeEvent overridden."""

    def __init__(self, parent=None):
        super(TestPlot1, self).__init__(parent)

        y = linspace(0, 2*pi, 500)

        curve = QwtPlotCurve('Test Curve')
        curve.setData(sin(y), y)
        curve.attach(self)

        self.replot()

class TestPlot2(QwtPlot):
    """With resizeEvent overridden."""

    def __init__(self, parent=None):
        super(TestPlot2, self).__init__(parent)

        y = linspace(0, 2*pi, 500)

        curve = QwtPlotCurve('Test Curve')
        curve.setData(sin(y), y)
        curve.attach(self)

        self.replot()

    def resizeEvent(self, event):
        QwtPlot.resizeEvent(self, event)
        self.replot()

if __name__ == '__main__':
    app = QApplication(argv)

    plot1 = TestPlot1()
    window1 = QMainWindow()
    window1.setWindowTitle("Without resizeEvent overridden")
    window1.setCentralWidget(plot1)
    window1.show()

    plot2 = TestPlot2()
    window2 = QMainWindow()
    window2.setWindowTitle("With resizeEvent overridden")
    window2.setCentralWidget(plot2)
    window2.show()

    exit(app.exec_())

And both plots resists resizing them smaller than what the current laid out axes permit. What I'm looking for is a way to be able to have the automatic axes divisions automatically updated to allow resizing it even smaller.