Comments (2)
Hi,
Thanks for the feedback.
Actually, the right way to do this is to set the axis limits using the QwtPlot.setAxisScale
method:
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QApplication, QSlider, QVBoxLayout, QWidget
from qwt import QwtPlot, QwtPlotCurve
app = QApplication([])
plot = QwtPlot()
QwtPlotCurve.make([0, 9], [0, 9], "", plot)
plot.setAxisScale(QwtPlot.xBottom, 0, 9)
slider = QSlider(Qt.Orientation.Horizontal)
slider.setRange(0, 9)
def change_lower_bound(value: int) -> None:
xint = plot.axisScaleDiv(QwtPlot.xBottom).interval()
plot.setAxisScale(QwtPlot.xBottom, value, xint.maxValue())
plot.replot()
slider.valueChanged.connect(change_lower_bound)
root = QWidget()
layout = QVBoxLayout(root)
root.setLayout(layout)
layout.addWidget(plot)
layout.addWidget(slider)
root.show()
app.exec()
And here is the recommended way of coding this:
import numpy as np
from PySide6 import QtCore as QC
from PySide6 import QtWidgets as QW
import qwt
class MyWidget(QW.QWidget):
"""A widget that contains a plot and a slider."""
def __init__(self, parent):
super().__init__(parent)
layout = QW.QVBoxLayout(self)
self.setLayout(layout)
self.plot = qwt.QwtPlot()
layout.addWidget(self.plot)
self.slider = QW.QSlider(QC.Qt.Horizontal)
self.slider.valueChanged.connect(self.__change_lower_bound)
layout.addWidget(self.slider)
def __change_lower_bound(self, value: int) -> None:
"""Change the lower bound of the x-axis."""
scalediv = self.plot.axisScaleDiv(qwt.QwtPlot.xBottom)
if scalediv is not None:
xint = scalediv.interval()
self.plot.setAxisScale(qwt.QwtPlot.xBottom, value, xint.maxValue())
self.plot.replot()
def set_curve(self, x, y, title):
"""Set the curve to be displayed in the plot."""
qwt.QwtPlotCurve.make(x, y, title, self.plot, linecolor="blue")
self.slider.setRange(x[0], x[-2])
self.slider.setValue(x[0])
def test_scroll_scalediv():
"""Test the scrolling of the x-axis scale division."""
app = QW.QApplication([])
widget = MyWidget(None)
widget.show()
x = np.linspace(-10, 10, 100)
y = np.sin(x)
widget.set_curve(x, y, "")
app.exec()
if __name__ == "__main__":
test_scroll_scalediv()
from pythonqwt.
xint = plot.axisScaleDiv(QwtPlot.xBottom).interval()
plot.setAxisScale(QwtPlot.xBottom, value, xint.maxValue())
thanks, that did the trick!
from pythonqwt.
Related Issues (20)
- Bugfixe : QSize + QSizeF
- support for PySide6 ? HOT 1
- Add support for PyQt6 HOT 2
- PyQt/NumPy types conflict
- Add input widgets and other features of Qwt
- AttributeError: 'QwtScaleWidget' object has no attribute 'maxMajor' / 'maxMinor' / 'stepSize'
- Actually NAME the library QwtMathMLTextEngine is provided by HOT 1
- TypeError: QwtPlotDict.__init__() [...] with PySide 6.5.0 HOT 9
- [PySide] AttributeError: 'QwtPlotCanvas' object has no attribute 'Sunken'
- AttributeError: 'XXX' object has no attribute '_QwtPlot__data'
- TypeError: unexpected type 'QSize' HOT 4
- Print to PDF: AttributeError: 'NoneType' object has no attribute 'getContentsMargins'
- Signal disconnection issue with PySide 6.5.3
- Plot markers: labels and symbols are clipped HOT 8
- Performance issue with High DPI displays HOT 6
- Add NumPy V2.0 support HOT 1
- `QwtAbstractScaleDraw` label cache mechanism can cause segmentation fault
- `QwtSymbol` constructor: segmentation fault on CentOS/Python3.12/PyQt5
- `QwtPlot.setMouseTracking` is ignored HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pythonqwt.