How to set trace name in pyqtgraph?









up vote
1
down vote

favorite












I am using this class to draw a trace, I've got 2 lines to trace, but I cannot display name of each line, how to?



class Plot2D():
def __init__(self):
self.traces = dict()

#QtGui.QApplication.setGraphicsSystem('raster')
self.app = QtGui.QApplication()
#mw = QtGui.QMainWindow()
#mw.resize(800,800)

self.win = pg.GraphicsWindow(title="Detecting cluck")
self.win.resize(1000,600)
self.win.setWindowTitle('Detecting')
# Enable antialiasing for prettier plots
pg.setConfigOptions(antialias=True)

self.canvas = self.win.addPlot(title="改装车检测")
self.canvas.setYRange(0, 1)

def start(self):
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()

def trace(self,name,dataset_x,dataset_y,sColor):
if name in self.traces:
self.traces[name].setData(dataset_x,dataset_y)
else:
self.traces[name] = self.canvas.plot(
pen=pg.mkPen(sColor, width=3), name="car")


what I got:



what I got





what I want:



enter image description here










share|improve this question



























    up vote
    1
    down vote

    favorite












    I am using this class to draw a trace, I've got 2 lines to trace, but I cannot display name of each line, how to?



    class Plot2D():
    def __init__(self):
    self.traces = dict()

    #QtGui.QApplication.setGraphicsSystem('raster')
    self.app = QtGui.QApplication()
    #mw = QtGui.QMainWindow()
    #mw.resize(800,800)

    self.win = pg.GraphicsWindow(title="Detecting cluck")
    self.win.resize(1000,600)
    self.win.setWindowTitle('Detecting')
    # Enable antialiasing for prettier plots
    pg.setConfigOptions(antialias=True)

    self.canvas = self.win.addPlot(title="改装车检测")
    self.canvas.setYRange(0, 1)

    def start(self):
    if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
    QtGui.QApplication.instance().exec_()

    def trace(self,name,dataset_x,dataset_y,sColor):
    if name in self.traces:
    self.traces[name].setData(dataset_x,dataset_y)
    else:
    self.traces[name] = self.canvas.plot(
    pen=pg.mkPen(sColor, width=3), name="car")


    what I got:



    what I got





    what I want:



    enter image description here










    share|improve this question

























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I am using this class to draw a trace, I've got 2 lines to trace, but I cannot display name of each line, how to?



      class Plot2D():
      def __init__(self):
      self.traces = dict()

      #QtGui.QApplication.setGraphicsSystem('raster')
      self.app = QtGui.QApplication()
      #mw = QtGui.QMainWindow()
      #mw.resize(800,800)

      self.win = pg.GraphicsWindow(title="Detecting cluck")
      self.win.resize(1000,600)
      self.win.setWindowTitle('Detecting')
      # Enable antialiasing for prettier plots
      pg.setConfigOptions(antialias=True)

      self.canvas = self.win.addPlot(title="改装车检测")
      self.canvas.setYRange(0, 1)

      def start(self):
      if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
      QtGui.QApplication.instance().exec_()

      def trace(self,name,dataset_x,dataset_y,sColor):
      if name in self.traces:
      self.traces[name].setData(dataset_x,dataset_y)
      else:
      self.traces[name] = self.canvas.plot(
      pen=pg.mkPen(sColor, width=3), name="car")


      what I got:



      what I got





      what I want:



      enter image description here










      share|improve this question















      I am using this class to draw a trace, I've got 2 lines to trace, but I cannot display name of each line, how to?



      class Plot2D():
      def __init__(self):
      self.traces = dict()

      #QtGui.QApplication.setGraphicsSystem('raster')
      self.app = QtGui.QApplication()
      #mw = QtGui.QMainWindow()
      #mw.resize(800,800)

      self.win = pg.GraphicsWindow(title="Detecting cluck")
      self.win.resize(1000,600)
      self.win.setWindowTitle('Detecting')
      # Enable antialiasing for prettier plots
      pg.setConfigOptions(antialias=True)

      self.canvas = self.win.addPlot(title="改装车检测")
      self.canvas.setYRange(0, 1)

      def start(self):
      if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
      QtGui.QApplication.instance().exec_()

      def trace(self,name,dataset_x,dataset_y,sColor):
      if name in self.traces:
      self.traces[name].setData(dataset_x,dataset_y)
      else:
      self.traces[name] = self.canvas.plot(
      pen=pg.mkPen(sColor, width=3), name="car")


      what I got:



      what I got





      what I want:



      enter image description here







      python pyqtgraph






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 12 at 3:34









      eyllanesc

      71.8k93054




      71.8k93054










      asked Nov 12 at 3:28









      Simon

      114




      114






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          You must use addLegend(), in addition to establishing a name in the plot:



          import sys
          from pyqtgraph.Qt import QtGui, QtCore
          import pyqtgraph as pg
          import numpy as np

          class Plot2D():
          def __init__(self):
          self.traces = dict()

          self.app = QtGui.QApplication()

          self.win = pg.GraphicsWindow(title="Detecting")
          self.win.resize(1000,600)
          pg.setConfigOptions(antialias=True)

          self.canvas = self.win.addPlot(title="改装车检测")
          self.canvas.addLegend()
          self.canvas.setYRange(0, 1)

          def start(self):
          if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
          QtGui.QApplication.instance().exec_()

          def trace(self,name,dataset_x,dataset_y,sColor):
          if name in self.traces:
          self.traces[name].setData(dataset_x,dataset_y)
          else:
          self.traces[name] = self.canvas.plot(dataset_x, dataset_y,
          pen=pg.mkPen(sColor, width=3), name=name)

          if __name__ == '__main__':
          p = Plot2D()
          p.trace("name1", range(100), 0.5 + np.random.normal(size=100, scale=0.1), 'r')
          p.trace("name2", range(100), 0.5 + np.random.normal(size=100, scale=0.1), 'w')
          p.start()


          enter image description here



          Update:



          If you want to change the font size you can use HTML



          self.traces[name] = self.canvas.plot(dataset_x, dataset_y,
          pen=pg.mkPen(sColor, width=3), name='''<font size="15"></font>'''.format(name))


          enter image description here






          share|improve this answer






















          • Thanks a lot, that's solve my problem。
            – Simon
            Nov 12 at 4:13










          • Could you tell me how to change the font size of legend?
            – Simon
            Nov 12 at 4:14










          • @Simon let me find out if you can change the font of the legend, on the other hand if my answer helps you do not forget to mark it as correct, if you do not know how to do it then review the tour, that is the best way to thank.
            – eyllanesc
            Nov 12 at 4:18










          • @Simon see my update.
            – eyllanesc
            Nov 12 at 4:31










          • Great! I have chosen you as the correct answer。
            – Simon
            Nov 12 at 6:25










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255595%2fhow-to-set-trace-name-in-pyqtgraph%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          You must use addLegend(), in addition to establishing a name in the plot:



          import sys
          from pyqtgraph.Qt import QtGui, QtCore
          import pyqtgraph as pg
          import numpy as np

          class Plot2D():
          def __init__(self):
          self.traces = dict()

          self.app = QtGui.QApplication()

          self.win = pg.GraphicsWindow(title="Detecting")
          self.win.resize(1000,600)
          pg.setConfigOptions(antialias=True)

          self.canvas = self.win.addPlot(title="改装车检测")
          self.canvas.addLegend()
          self.canvas.setYRange(0, 1)

          def start(self):
          if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
          QtGui.QApplication.instance().exec_()

          def trace(self,name,dataset_x,dataset_y,sColor):
          if name in self.traces:
          self.traces[name].setData(dataset_x,dataset_y)
          else:
          self.traces[name] = self.canvas.plot(dataset_x, dataset_y,
          pen=pg.mkPen(sColor, width=3), name=name)

          if __name__ == '__main__':
          p = Plot2D()
          p.trace("name1", range(100), 0.5 + np.random.normal(size=100, scale=0.1), 'r')
          p.trace("name2", range(100), 0.5 + np.random.normal(size=100, scale=0.1), 'w')
          p.start()


          enter image description here



          Update:



          If you want to change the font size you can use HTML



          self.traces[name] = self.canvas.plot(dataset_x, dataset_y,
          pen=pg.mkPen(sColor, width=3), name='''<font size="15"></font>'''.format(name))


          enter image description here






          share|improve this answer






















          • Thanks a lot, that's solve my problem。
            – Simon
            Nov 12 at 4:13










          • Could you tell me how to change the font size of legend?
            – Simon
            Nov 12 at 4:14










          • @Simon let me find out if you can change the font of the legend, on the other hand if my answer helps you do not forget to mark it as correct, if you do not know how to do it then review the tour, that is the best way to thank.
            – eyllanesc
            Nov 12 at 4:18










          • @Simon see my update.
            – eyllanesc
            Nov 12 at 4:31










          • Great! I have chosen you as the correct answer。
            – Simon
            Nov 12 at 6:25














          up vote
          0
          down vote



          accepted










          You must use addLegend(), in addition to establishing a name in the plot:



          import sys
          from pyqtgraph.Qt import QtGui, QtCore
          import pyqtgraph as pg
          import numpy as np

          class Plot2D():
          def __init__(self):
          self.traces = dict()

          self.app = QtGui.QApplication()

          self.win = pg.GraphicsWindow(title="Detecting")
          self.win.resize(1000,600)
          pg.setConfigOptions(antialias=True)

          self.canvas = self.win.addPlot(title="改装车检测")
          self.canvas.addLegend()
          self.canvas.setYRange(0, 1)

          def start(self):
          if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
          QtGui.QApplication.instance().exec_()

          def trace(self,name,dataset_x,dataset_y,sColor):
          if name in self.traces:
          self.traces[name].setData(dataset_x,dataset_y)
          else:
          self.traces[name] = self.canvas.plot(dataset_x, dataset_y,
          pen=pg.mkPen(sColor, width=3), name=name)

          if __name__ == '__main__':
          p = Plot2D()
          p.trace("name1", range(100), 0.5 + np.random.normal(size=100, scale=0.1), 'r')
          p.trace("name2", range(100), 0.5 + np.random.normal(size=100, scale=0.1), 'w')
          p.start()


          enter image description here



          Update:



          If you want to change the font size you can use HTML



          self.traces[name] = self.canvas.plot(dataset_x, dataset_y,
          pen=pg.mkPen(sColor, width=3), name='''<font size="15"></font>'''.format(name))


          enter image description here






          share|improve this answer






















          • Thanks a lot, that's solve my problem。
            – Simon
            Nov 12 at 4:13










          • Could you tell me how to change the font size of legend?
            – Simon
            Nov 12 at 4:14










          • @Simon let me find out if you can change the font of the legend, on the other hand if my answer helps you do not forget to mark it as correct, if you do not know how to do it then review the tour, that is the best way to thank.
            – eyllanesc
            Nov 12 at 4:18










          • @Simon see my update.
            – eyllanesc
            Nov 12 at 4:31










          • Great! I have chosen you as the correct answer。
            – Simon
            Nov 12 at 6:25












          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          You must use addLegend(), in addition to establishing a name in the plot:



          import sys
          from pyqtgraph.Qt import QtGui, QtCore
          import pyqtgraph as pg
          import numpy as np

          class Plot2D():
          def __init__(self):
          self.traces = dict()

          self.app = QtGui.QApplication()

          self.win = pg.GraphicsWindow(title="Detecting")
          self.win.resize(1000,600)
          pg.setConfigOptions(antialias=True)

          self.canvas = self.win.addPlot(title="改装车检测")
          self.canvas.addLegend()
          self.canvas.setYRange(0, 1)

          def start(self):
          if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
          QtGui.QApplication.instance().exec_()

          def trace(self,name,dataset_x,dataset_y,sColor):
          if name in self.traces:
          self.traces[name].setData(dataset_x,dataset_y)
          else:
          self.traces[name] = self.canvas.plot(dataset_x, dataset_y,
          pen=pg.mkPen(sColor, width=3), name=name)

          if __name__ == '__main__':
          p = Plot2D()
          p.trace("name1", range(100), 0.5 + np.random.normal(size=100, scale=0.1), 'r')
          p.trace("name2", range(100), 0.5 + np.random.normal(size=100, scale=0.1), 'w')
          p.start()


          enter image description here



          Update:



          If you want to change the font size you can use HTML



          self.traces[name] = self.canvas.plot(dataset_x, dataset_y,
          pen=pg.mkPen(sColor, width=3), name='''<font size="15"></font>'''.format(name))


          enter image description here






          share|improve this answer














          You must use addLegend(), in addition to establishing a name in the plot:



          import sys
          from pyqtgraph.Qt import QtGui, QtCore
          import pyqtgraph as pg
          import numpy as np

          class Plot2D():
          def __init__(self):
          self.traces = dict()

          self.app = QtGui.QApplication()

          self.win = pg.GraphicsWindow(title="Detecting")
          self.win.resize(1000,600)
          pg.setConfigOptions(antialias=True)

          self.canvas = self.win.addPlot(title="改装车检测")
          self.canvas.addLegend()
          self.canvas.setYRange(0, 1)

          def start(self):
          if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
          QtGui.QApplication.instance().exec_()

          def trace(self,name,dataset_x,dataset_y,sColor):
          if name in self.traces:
          self.traces[name].setData(dataset_x,dataset_y)
          else:
          self.traces[name] = self.canvas.plot(dataset_x, dataset_y,
          pen=pg.mkPen(sColor, width=3), name=name)

          if __name__ == '__main__':
          p = Plot2D()
          p.trace("name1", range(100), 0.5 + np.random.normal(size=100, scale=0.1), 'r')
          p.trace("name2", range(100), 0.5 + np.random.normal(size=100, scale=0.1), 'w')
          p.start()


          enter image description here



          Update:



          If you want to change the font size you can use HTML



          self.traces[name] = self.canvas.plot(dataset_x, dataset_y,
          pen=pg.mkPen(sColor, width=3), name='''<font size="15"></font>'''.format(name))


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 12 at 4:30

























          answered Nov 12 at 3:55









          eyllanesc

          71.8k93054




          71.8k93054











          • Thanks a lot, that's solve my problem。
            – Simon
            Nov 12 at 4:13










          • Could you tell me how to change the font size of legend?
            – Simon
            Nov 12 at 4:14










          • @Simon let me find out if you can change the font of the legend, on the other hand if my answer helps you do not forget to mark it as correct, if you do not know how to do it then review the tour, that is the best way to thank.
            – eyllanesc
            Nov 12 at 4:18










          • @Simon see my update.
            – eyllanesc
            Nov 12 at 4:31










          • Great! I have chosen you as the correct answer。
            – Simon
            Nov 12 at 6:25
















          • Thanks a lot, that's solve my problem。
            – Simon
            Nov 12 at 4:13










          • Could you tell me how to change the font size of legend?
            – Simon
            Nov 12 at 4:14










          • @Simon let me find out if you can change the font of the legend, on the other hand if my answer helps you do not forget to mark it as correct, if you do not know how to do it then review the tour, that is the best way to thank.
            – eyllanesc
            Nov 12 at 4:18










          • @Simon see my update.
            – eyllanesc
            Nov 12 at 4:31










          • Great! I have chosen you as the correct answer。
            – Simon
            Nov 12 at 6:25















          Thanks a lot, that's solve my problem。
          – Simon
          Nov 12 at 4:13




          Thanks a lot, that's solve my problem。
          – Simon
          Nov 12 at 4:13












          Could you tell me how to change the font size of legend?
          – Simon
          Nov 12 at 4:14




          Could you tell me how to change the font size of legend?
          – Simon
          Nov 12 at 4:14












          @Simon let me find out if you can change the font of the legend, on the other hand if my answer helps you do not forget to mark it as correct, if you do not know how to do it then review the tour, that is the best way to thank.
          – eyllanesc
          Nov 12 at 4:18




          @Simon let me find out if you can change the font of the legend, on the other hand if my answer helps you do not forget to mark it as correct, if you do not know how to do it then review the tour, that is the best way to thank.
          – eyllanesc
          Nov 12 at 4:18












          @Simon see my update.
          – eyllanesc
          Nov 12 at 4:31




          @Simon see my update.
          – eyllanesc
          Nov 12 at 4:31












          Great! I have chosen you as the correct answer。
          – Simon
          Nov 12 at 6:25




          Great! I have chosen you as the correct answer。
          – Simon
          Nov 12 at 6:25

















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53255595%2fhow-to-set-trace-name-in-pyqtgraph%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Top Tejano songwriter Luis Silva dead of heart attack at 64

          ReactJS Fetched API data displays live - need Data displayed static

          政党