Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why pyqtgraph legend text cannot contain '>', '<=', etc

I am plotting data with pyqtgraph inside a PySide6 Application.
Anyways, the problem is that the text gets cut off if a name contains a special character like ‘>’.

Here is a minimal example:

from PySide6 import QtCore, QtWidgets
import pyqtgraph as pg

plt = pg.plot()
plt.addLegend()

c1 = plt.plot([1,2,3], pen='r', name="TEST_O<C_C*0.99>=H")
c2 = plt.plot([3,2,1], pen='g', name='green plot test blabla')

if __name__ == '__main__':
    import sys
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        QtWidgets.QApplication.instance().exec()

Which outputs:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

Why does this happen?
Is there a work-around without replacing the characters?

>Solution :

I’d wager it’s being interpreted as an HTML tag.

Try "TEST_O&lt;C_C*0.99&gt;=H", or, programmatically,

import html
# ...
c1 = plt.plot([1,2,3], pen='r', name=html.escape("TEST_O<C_C*0.99>=H"))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading