Unsolved Switching charts on toggle takes too much time
-
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.
-
@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
-
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.
-
@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?
-
@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.
-
@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.
-
@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?