Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

taurus tpg plot: curve names in legend cannot be changed #31

Closed
mrosanes opened this issue Jul 25, 2019 · 5 comments · Fixed by #80
Closed

taurus tpg plot: curve names in legend cannot be changed #31

mrosanes opened this issue Jul 25, 2019 · 5 comments · Fixed by #80
Labels
enhancement New feature or request

Comments

@mrosanes
Copy link

Bug found during manual tests on win10 py3qt5 Jul19 release:

taurus tpg plot: curve names in legend cannot be changed
Even when clicking to 'apply', the curve titles are not changed in the legend

@mrosanes
Copy link
Author

This option is not yet ready in pyqtgraph

@cpascual cpascual changed the title taurus tpg plot: curve names in legend cannot be changed (win10) taurus tpg plot: curve names in legend cannot be changed Jul 29, 2019
@cpascual cpascual added the enhancement New feature or request label Jul 29, 2019
@cpascual
Copy link
Member

None of the 3 possible methods work yet:

  • Plot Configuration dialog --> editing the name of the curve in the list
  • Plot Configuration dialog -->"Curve Titles..." button
  • Model Selection Dialog, edit title column

cpascual pushed a commit to cpascual/taurus_pyqtgraph that referenced this issue Nov 5, 2020
Editions of the curve titles in the curves list widget are
now applied on "Apply".

Fixes taurus-org#31
@cpascual cpascual mentioned this issue Nov 5, 2020
@mariocaptain
Copy link

mariocaptain commented Feb 9, 2021

Is it possible now to change/set the legends of curves in code? In my TaurusTrend panel I have 4 curves, whose data set by the addModels method of TaurusTrend and I haven't found a way to change the legends of the models to a more friendly representation in code, other than using the Plot Configuration dialog. Being able to set in code would be much for useful than using the dialog. I have been trying to access the LegendItem objects of the curves in code to set their text to no avail.
Thanks.

@cpascual
Copy link
Member

cpascual commented Feb 9, 2021

Is it possible now to change/set the legends of curves in code?

Hi, @mariocaptain , you can do it, but it is not trivial.
Here is a snippet demonstrating it ( adapted from the code in taurus_pyqtgraph.curveproperties.set_properties_on_curves()):

from taurus.qt.qtgui.application import TaurusApplication
from taurus_pyqtgraph import TaurusPlot
import sys


def change_curve_name(title, curve, plotItem):
    # change curve title
    curve.setData(name=title)
    # update legend (if it exists)
    if plotItem.legend is not None:
        if hasattr(plotItem.legend, "getLabel"):  # requires pyqtgraph > 0.11
            plotItem.legend.getLabel(curve).setText(title)
        else:  # for pyqtgraph <= 0.11
            for sample, label in plotItem.legend.items:
                if sample.item == curve:
                    label.setText(title)
                    break

app = TaurusApplication(cmd_line_parser=None)
w = TaurusPlot()
w.setModel(["eval:rand(33)", "eval:2+rand(33)"])
change_curve_name("foo", w[0], w.getPlotItem())
change_curve_name("bar", w[1], w.getPlotItem())
w.show()
sys.exit(app.exec_())

@mariocaptain
Copy link

Dear @cpascual ,

Thanks so much for the time. The function works very well. I am so happy with TaurusTrend now :)

Best,
Dave

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants