question!

34 views
Skip to first unread message

Valentina Colmenarez

unread,
Aug 16, 2022, 11:20:20 AM8/16/22
to pyqtgraph
  Hi! I have a question, regarding an update I need to do on a chart.

I need to update the information of the chart on a secondary window when pressing any key.  For that I'm using the "os.system("pause")" method, which I understand is like the "pause()" method in Matlab. However, the "os.system("pause")" disables the main window of my program. Is there any another method I can use to help me with the current update I need to do?.

Thank you in advance.

Ognyan Moore

unread,
Aug 22, 2022, 10:33:47 AM8/22/22
to pyqt...@googlegroups.com
Hi, sorry I just realized you didn't get a response here.  I haven't used matlab in quite some time, and even when I did use it, I wasn't particularly proficient with it, so I'm not going to be of much use in providing analogous functionality, but I can certainly help w/ some guidance on how to update plots in pyqtgraph.

Most of pyqtgraph's plot objects have a setData method intended to be called with new data to update an existing plot with.  The easiest way to update a plot would be to use a signal/slot mechanism where new data is emitted with a signal and where the setData method is treated as the slot that receives the new data.  This should update the plot accordingly.

Sometimes when we want a plot updating at a fixed interval (or as quickly as possible), you can use a QTimer.  We use QTimer's throughout our examples, you can see a use-case here: https://github.com/pyqtgraph/pyqtgraph/blob/master/pyqtgraph/examples/PlotSpeedTest.py

I haven't ever used os.system("pause") before, and I would think this is likely not the method you actually want to use in your case.

--
You received this message because you are subscribed to the Google Groups "pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/9dc1f5dc-d4a3-4df6-bb35-be8d2a47598bn%40googlegroups.com.

Martin Chase

unread,
Aug 22, 2022, 12:46:15 PM8/22/22
to pyqt...@googlegroups.com
Hey Valentina,

Here's a bit of code to help illustrate what Ogi is describing, for the case where the one window has a signal handler.

```python
class A(QtWidget):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._data_plot_in_window_b = None

    def set_data_plot_to_update(self, plot):
        self._data_plot_in_window_b = plot

    def handleKeyPressEvent(self, ev):
        if ev.key() == Qt.Key_Up and self._data_plot_in_window_b is not None:
            self._data_plot_in_window_b.setData(self.some_new_data())

    def some_new_data(self):
        return np.random.normal(size=self._data_plot_in_window_b.shape)

a = A()
a.set_data_plot_to_update(b.plot)
```

Good luck,
 - Martin
Reply all
Reply to author
Forward
0 new messages