Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for geometry based axis auto-scaling #39

Open
estan opened this issue Mar 10, 2016 · 3 comments
Open

Add support for geometry based axis auto-scaling #39

estan opened this issue Mar 10, 2016 · 3 comments
Labels

Comments

@estan
Copy link

estan commented Mar 10, 2016

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
Copy link
Collaborator

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
Copy link
Author

estan commented Mar 10, 2016

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
Copy link
Author

estan commented Mar 10, 2016

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants