Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Switching charts on toggle takes too much time
Forum Updated to NodeBB v4.3 + New Features

Switching charts on toggle takes too much time

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Piyush
    wrote on last edited by Piyush
    #1

    Hi,

    I need to update charts depending upon the toggle selected. The functionality is working however, it takes a lot of time (5-10 secs) to update a chart. Following is the code i am currently using:

            if self.ui.radio_ABC.isChecked():
                     temp = Variable_ABC
            if self.ui.radio_XYZ.isChecked():
                     temp = Variable_XYZ
    
            years = mdates.YearLocator()   # every year
            months = mdates.MonthLocator()  # every month
            yearsFmt = mdates.DateFormatter('%Y')
            
            self.ui.chart1.canvas.ax7.xaxis.set_major_locator(years)
            self.ui.chart1.canvas.ax7.xaxis.set_major_formatter(months)
            self.ui.chart1.canvas.ax7.xaxis.set_minor_locator(yearsFmt)
            self.ui.chart1.canvas.ax7.grid(True)
            
            self.ui.chart1.canvas.ax7.plot(temp.iloc[:, 1], label = "ABC", color = 'crimson')
            self.ui.chart1.canvas.ax7.plot(temp.iloc[:, 0], label = "XYZ", color = 'blue')
            self.ui.chart1.canvas.ax6.plot(temp.iloc[:, 2], label = "DEF", color = 'gray', linewidth = 3.0)
            
            self.ui.chart1.canvas.ax6.axhline((temp.iloc[:, 2].quantile(0.50)), color = 'skyblue', linestyle = '-', linewidth = 3.0, label = 'GHI')        
            self.ui.chart1.canvas.ax6.axhline((temp.iloc[:, 2].quantile(0.75)), color = 'skyblue', linestyle = '-', linewidth = 1.5, label = 'HIJ')
            self.ui.chart1.canvas.ax6.axhline((temp.iloc[:, 2].quantile(0.25)), color = 'skyblue', linestyle = '-', linewidth = 1.5, label = 'IJK')
            
            self.ui.chart1.canvas.ax7.set_ylabel('IJK %s' % (temp.name))
            self.ui.chart1.canvas.ax6.set_ylabel('LMO')
            self.ui.chart1.canvas.ax7.set_title('NPQ %s' % (temp.name), loc = 'left', x = 0.1, y = 0.85, fontsize = "12", fontweight = 'bold')
            
            self.ui.chart1.canvas.ax6.legend(loc = 'upper center', bbox_to_anchor = (0.7, -0.08), ncol = 10)
            self.ui.chart1.canvas.ax7.legend(loc = 'upper center', bbox_to_anchor = (0.12, -0.08), ncol = 10)
            
            datacursor(self.ui.chart1.canvas.ax6.plot(temp.iloc[:, 2], '.', markersize = 0), hover = True)
            datacursor(self.ui.chart1.canvas.ax7.plot(temp.iloc[:, 0], '.', markersize = 0), hover = True)
            datacursor(self.ui.chart1.canvas.ax7.plot(temp.iloc[:, 1], '.', markersize = 0), hover = True)
    

    I am not sure, which line of code is creating a problem/ taking too much time to update. Could you please help?

    Even if i try to set the charts to visible or invisible one the basis of radio button selection, still it takes a lot of time.

    jsulmJ JonBJ 2 Replies Last reply
    0
    • P Piyush

      Hi,

      I need to update charts depending upon the toggle selected. The functionality is working however, it takes a lot of time (5-10 secs) to update a chart. Following is the code i am currently using:

              if self.ui.radio_ABC.isChecked():
                       temp = Variable_ABC
              if self.ui.radio_XYZ.isChecked():
                       temp = Variable_XYZ
      
              years = mdates.YearLocator()   # every year
              months = mdates.MonthLocator()  # every month
              yearsFmt = mdates.DateFormatter('%Y')
              
              self.ui.chart1.canvas.ax7.xaxis.set_major_locator(years)
              self.ui.chart1.canvas.ax7.xaxis.set_major_formatter(months)
              self.ui.chart1.canvas.ax7.xaxis.set_minor_locator(yearsFmt)
              self.ui.chart1.canvas.ax7.grid(True)
              
              self.ui.chart1.canvas.ax7.plot(temp.iloc[:, 1], label = "ABC", color = 'crimson')
              self.ui.chart1.canvas.ax7.plot(temp.iloc[:, 0], label = "XYZ", color = 'blue')
              self.ui.chart1.canvas.ax6.plot(temp.iloc[:, 2], label = "DEF", color = 'gray', linewidth = 3.0)
              
              self.ui.chart1.canvas.ax6.axhline((temp.iloc[:, 2].quantile(0.50)), color = 'skyblue', linestyle = '-', linewidth = 3.0, label = 'GHI')        
              self.ui.chart1.canvas.ax6.axhline((temp.iloc[:, 2].quantile(0.75)), color = 'skyblue', linestyle = '-', linewidth = 1.5, label = 'HIJ')
              self.ui.chart1.canvas.ax6.axhline((temp.iloc[:, 2].quantile(0.25)), color = 'skyblue', linestyle = '-', linewidth = 1.5, label = 'IJK')
              
              self.ui.chart1.canvas.ax7.set_ylabel('IJK %s' % (temp.name))
              self.ui.chart1.canvas.ax6.set_ylabel('LMO')
              self.ui.chart1.canvas.ax7.set_title('NPQ %s' % (temp.name), loc = 'left', x = 0.1, y = 0.85, fontsize = "12", fontweight = 'bold')
              
              self.ui.chart1.canvas.ax6.legend(loc = 'upper center', bbox_to_anchor = (0.7, -0.08), ncol = 10)
              self.ui.chart1.canvas.ax7.legend(loc = 'upper center', bbox_to_anchor = (0.12, -0.08), ncol = 10)
              
              datacursor(self.ui.chart1.canvas.ax6.plot(temp.iloc[:, 2], '.', markersize = 0), hover = True)
              datacursor(self.ui.chart1.canvas.ax7.plot(temp.iloc[:, 0], '.', markersize = 0), hover = True)
              datacursor(self.ui.chart1.canvas.ax7.plot(temp.iloc[:, 1], '.', markersize = 0), hover = True)
      

      I am not sure, which line of code is creating a problem/ taking too much time to update. Could you please help?

      Even if i try to set the charts to visible or invisible one the basis of radio button selection, still it takes a lot of time.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Piyush said in Switching charts on toggle takes too much time:

      I am not sure, which line of code is creating a problem/ taking too much time to update

      For that there is https://docs.python.org/2/library/profile.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • 6thC6 Offline
        6thC6 Offline
        6thC
        wrote on last edited by
        #3

        I don't see where you're actually drawing /defining your series. I expect if it's like QML charts: canvas sucks for fast updates. If you can use OpenGL lines I'd recommend that.

        A google search results in : https://github.com/PierreRaybaut/plotpy/wiki/Using-Qt-Charts-(PyQtChart)-to-plot-curves-efficiently-in-Python! - looks like it is an option.

        1 Reply Last reply
        1
        • P Piyush

          Hi,

          I need to update charts depending upon the toggle selected. The functionality is working however, it takes a lot of time (5-10 secs) to update a chart. Following is the code i am currently using:

                  if self.ui.radio_ABC.isChecked():
                           temp = Variable_ABC
                  if self.ui.radio_XYZ.isChecked():
                           temp = Variable_XYZ
          
                  years = mdates.YearLocator()   # every year
                  months = mdates.MonthLocator()  # every month
                  yearsFmt = mdates.DateFormatter('%Y')
                  
                  self.ui.chart1.canvas.ax7.xaxis.set_major_locator(years)
                  self.ui.chart1.canvas.ax7.xaxis.set_major_formatter(months)
                  self.ui.chart1.canvas.ax7.xaxis.set_minor_locator(yearsFmt)
                  self.ui.chart1.canvas.ax7.grid(True)
                  
                  self.ui.chart1.canvas.ax7.plot(temp.iloc[:, 1], label = "ABC", color = 'crimson')
                  self.ui.chart1.canvas.ax7.plot(temp.iloc[:, 0], label = "XYZ", color = 'blue')
                  self.ui.chart1.canvas.ax6.plot(temp.iloc[:, 2], label = "DEF", color = 'gray', linewidth = 3.0)
                  
                  self.ui.chart1.canvas.ax6.axhline((temp.iloc[:, 2].quantile(0.50)), color = 'skyblue', linestyle = '-', linewidth = 3.0, label = 'GHI')        
                  self.ui.chart1.canvas.ax6.axhline((temp.iloc[:, 2].quantile(0.75)), color = 'skyblue', linestyle = '-', linewidth = 1.5, label = 'HIJ')
                  self.ui.chart1.canvas.ax6.axhline((temp.iloc[:, 2].quantile(0.25)), color = 'skyblue', linestyle = '-', linewidth = 1.5, label = 'IJK')
                  
                  self.ui.chart1.canvas.ax7.set_ylabel('IJK %s' % (temp.name))
                  self.ui.chart1.canvas.ax6.set_ylabel('LMO')
                  self.ui.chart1.canvas.ax7.set_title('NPQ %s' % (temp.name), loc = 'left', x = 0.1, y = 0.85, fontsize = "12", fontweight = 'bold')
                  
                  self.ui.chart1.canvas.ax6.legend(loc = 'upper center', bbox_to_anchor = (0.7, -0.08), ncol = 10)
                  self.ui.chart1.canvas.ax7.legend(loc = 'upper center', bbox_to_anchor = (0.12, -0.08), ncol = 10)
                  
                  datacursor(self.ui.chart1.canvas.ax6.plot(temp.iloc[:, 2], '.', markersize = 0), hover = True)
                  datacursor(self.ui.chart1.canvas.ax7.plot(temp.iloc[:, 0], '.', markersize = 0), hover = True)
                  datacursor(self.ui.chart1.canvas.ax7.plot(temp.iloc[:, 1], '.', markersize = 0), hover = True)
          

          I am not sure, which line of code is creating a problem/ taking too much time to update. Could you please help?

          Even if i try to set the charts to visible or invisible one the basis of radio button selection, still it takes a lot of time.

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Piyush said in Switching charts on toggle takes too much time:

          Even if i try to set the charts to visible or invisible one the basis of radio button selection, still it takes a lot of time.

          Not sure what you are doing for this. But since you don't want to redraw, have you tried have 2 separate charts, one drawn each way, and swapping between showing them?

          P 1 Reply Last reply
          0
          • JonBJ JonB

            @Piyush said in Switching charts on toggle takes too much time:

            Even if i try to set the charts to visible or invisible one the basis of radio button selection, still it takes a lot of time.

            Not sure what you are doing for this. But since you don't want to redraw, have you tried have 2 separate charts, one drawn each way, and swapping between showing them?

            P Offline
            P Offline
            Piyush
            wrote on last edited by
            #5

            @JonB Yes, i tried doing that. However, switching is also taking the same amount of time.
            I guess it might be due to the module not able to pick fast updates.

            @6thC I am currently using matplotlib library/module. I guess that is not quiet efficient as compared to OpenGL which is causing the problem.

            JonBJ 1 Reply Last reply
            0
            • P Piyush

              @JonB Yes, i tried doing that. However, switching is also taking the same amount of time.
              I guess it might be due to the module not able to pick fast updates.

              @6thC I am currently using matplotlib library/module. I guess that is not quiet efficient as compared to OpenGL which is causing the problem.

              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by
              #6

              @Piyush said in Switching charts on toggle takes too much time:

              @JonB Yes, i tried doing that. However, switching is also taking the same amount of time.

              Depends on how you show/hide, I would have thought. I meant: get it to fully draw both charts first, sounds like whatever you are doing is redrawing.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                Piyush
                wrote on last edited by
                #7

                @JonB i tried drawing both chart and then just the show/hide operation but then again there is a lag. I used two different axis, as the axis will vary depending upon the data. A simple research says that, it take time to redraw labels and axis. Does that mean hiding and showing axis will also take time to update?

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved