Dynamically update Title

166 views
Skip to first unread message

Hikmet Sezen

unread,
Oct 2, 2022, 5:31:26 PM10/2/22
to pyqtgraph
Hi,
I need dynamically update plot title on a grid and MultiplePlotAxes (depend on request) plot for live streaming data follow. I would like to change title whether the plot has MultiplePlotAxes or not, but I could not figure out how to get current plot title and update it.

For simplicity code snippet from example of pyqtgraph:

import pyqtgraph as pg
pg.mkQApp()

pw = pg.PlotWidget(title='need to be update dynamically title :(')
pw.show()
p1 = pw.plotItem
p1.setLabels(left='axis 1')

p2 = pg.ViewBox()
p1.showAxis('right')
p1.scene().addItem(p2)
p1.getAxis('right').linkToView(p2)
p2.setXLink(p1)
p1.getAxis('right').setLabel('axis2', color='#0000ff')

def updateViews():
p2.setGeometry(p1.vb.sceneBoundingRect())
p2.linkedViewChanged(p1.vb, p2.XAxis)

updateViews()
p2.addItem(pg.PlotCurveItem([10, 20, 40, 80, 40, 20], pen='b'))
p1.plot([1, 2, 4, 8, 16, 32])
pg.exec()

 


Martin Chase

unread,
Oct 2, 2022, 5:37:55 PM10/2/22
to pyqt...@googlegroups.com
Heya,

Is what you're looking for something like `pw.setTitle("dynamic title here")`?


Best,
 - Martin

Hikmet Sezen

unread,
Oct 2, 2022, 5:51:36 PM10/2/22
to pyqt...@googlegroups.com
Thanks Martin,  `pw.setTitle("dynamic title here") works very well, but I forgot to ask an actually important part of my problem. Is there a way to achieve the current title "xxx.getTitle()", and then update it?

--
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/CAD_p8v33R8XBgYwbRbfQAf9gV7Z_gj5T2rXArHsvJ%2BSmXYST1A%40mail.gmail.com.

Martin Chase

unread,
Oct 2, 2022, 6:00:26 PM10/2/22
to pyqt...@googlegroups.com
Ah, yeah, `pw.plotItem.titleLabel.text` should have that value (though it shouldn't hurt to set the title multiple times to the same string). This should work well enough, but I worry that a title string is a poor piece of data on which to hang application logic. If you're trying to test for e.g. `isinstance(pw, MultiPlotWidget)`, something more explicit about that test might be a better choice.

Cheers!
 - Martin

Hikmet Sezen

unread,
Oct 2, 2022, 6:05:31 PM10/2/22
to pyqt...@googlegroups.com
"pw.plotItem.titleLabel.text" is the answer I am looking for. Thanks a lot :)

--
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.
Reply all
Reply to author
Forward
0 new messages