##// END OF EJS Templates
Optimize plots
jespinoza -
r1269:ad3b2d103f49
parent child
Show More
@@ -205,6 +205,7 class Plot(Operation):
205 self.ymax = kwargs.get('ymax', None)
205 self.ymax = kwargs.get('ymax', None)
206 self.yscale = kwargs.get('yscale', None)
206 self.yscale = kwargs.get('yscale', None)
207 self.xlabel = kwargs.get('xlabel', None)
207 self.xlabel = kwargs.get('xlabel', None)
208 self.attr_time = kwargs.get('attr_time', 'utctime')
208 self.decimation = kwargs.get('decimation', None)
209 self.decimation = kwargs.get('decimation', None)
209 self.showSNR = kwargs.get('showSNR', False)
210 self.showSNR = kwargs.get('showSNR', False)
210 self.oneFigure = kwargs.get('oneFigure', True)
211 self.oneFigure = kwargs.get('oneFigure', True)
@@ -304,8 +305,8 class Plot(Operation):
304 else:
305 else:
305 cmap = plt.get_cmap(self.colormap)
306 cmap = plt.get_cmap(self.colormap)
306 cmap.set_bad(self.bgcolor, 1.)
307 cmap.set_bad(self.bgcolor, 1.)
307 self.cmaps.append(cmap)
308 self.cmaps.append(cmap)
308
309
309 for fig in self.figures:
310 for fig in self.figures:
310 fig.canvas.mpl_connect('key_press_event', self.OnKeyPress)
311 fig.canvas.mpl_connect('key_press_event', self.OnKeyPress)
311 fig.canvas.mpl_connect('scroll_event', self.OnBtnScroll)
312 fig.canvas.mpl_connect('scroll_event', self.OnBtnScroll)
@@ -468,7 +469,8 class Plot(Operation):
468 else:
469 else:
469 if self.xaxis is 'time':
470 if self.xaxis is 'time':
470 dt = self.getDateTime(self.data.max_time)
471 dt = self.getDateTime(self.data.max_time)
471 xmax = (dt.replace(hour=int(self.xmax), minute=59, second=59) -
472 xmax = self.xmax - 1
473 xmax = (dt.replace(hour=int(xmax), minute=59, second=59) -
472 datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=1)).total_seconds()
474 datetime.datetime(1970, 1, 1) + datetime.timedelta(seconds=1)).total_seconds()
473 if self.data.localtime:
475 if self.data.localtime:
474 xmax += time.timezone
476 xmax += time.timezone
@@ -477,44 +479,41 class Plot(Operation):
477
479
478 ymin = self.ymin if self.ymin else numpy.nanmin(self.y)
480 ymin = self.ymin if self.ymin else numpy.nanmin(self.y)
479 ymax = self.ymax if self.ymax else numpy.nanmax(self.y)
481 ymax = self.ymax if self.ymax else numpy.nanmax(self.y)
480 #Y = numpy.array([1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000, 50000])
481
482 #i = 1 if numpy.where(
483 # abs(ymax-ymin) <= Y)[0][0] < 0 else numpy.where(abs(ymax-ymin) <= Y)[0][0]
484 #ystep = Y[i] / 10.
485 dig = int(numpy.log10(ymax))
486 if dig == 0:
487 digD = len(str(ymax)) - 2
488 ydec = ymax*(10**digD)
489
490 dig = int(numpy.log10(ydec))
491 ystep = ((ydec + (10**(dig)))//10**(dig))*(10**(dig))
492 ystep = ystep/5
493 ystep = ystep/(10**digD)
494
495 else:
496 ystep = ((ymax + (10**(dig)))//10**(dig))*(10**(dig))
497 ystep = ystep/5
498
499 if self.xaxis is not 'time':
500
501 dig = int(numpy.log10(xmax))
502
503 if dig <= 0:
504 digD = len(str(xmax)) - 2
505 xdec = xmax*(10**digD)
506
507 dig = int(numpy.log10(xdec))
508 xstep = ((xdec + (10**(dig)))//10**(dig))*(10**(dig))
509 xstep = xstep*0.5
510 xstep = xstep/(10**digD)
511
512 else:
513 xstep = ((xmax + (10**(dig)))//10**(dig))*(10**(dig))
514 xstep = xstep/5
515
482
516 for n, ax in enumerate(self.axes):
483 for n, ax in enumerate(self.axes):
517 if ax.firsttime:
484 if ax.firsttime:
485
486 dig = int(numpy.log10(ymax))
487 if dig == 0:
488 digD = len(str(ymax)) - 2
489 ydec = ymax*(10**digD)
490
491 dig = int(numpy.log10(ydec))
492 ystep = ((ydec + (10**(dig)))//10**(dig))*(10**(dig))
493 ystep = ystep/5
494 ystep = ystep/(10**digD)
495
496 else:
497 ystep = ((ymax + (10**(dig)))//10**(dig))*(10**(dig))
498 ystep = ystep/5
499
500 if self.xaxis is not 'time':
501
502 dig = int(numpy.log10(xmax))
503
504 if dig <= 0:
505 digD = len(str(xmax)) - 2
506 xdec = xmax*(10**digD)
507
508 dig = int(numpy.log10(xdec))
509 xstep = ((xdec + (10**(dig)))//10**(dig))*(10**(dig))
510 xstep = xstep*0.5
511 xstep = xstep/(10**digD)
512
513 else:
514 xstep = ((xmax + (10**(dig)))//10**(dig))*(10**(dig))
515 xstep = xstep/5
516
518 ax.set_facecolor(self.bgcolor)
517 ax.set_facecolor(self.bgcolor)
519 ax.yaxis.set_major_locator(MultipleLocator(ystep))
518 ax.yaxis.set_major_locator(MultipleLocator(ystep))
520 if self.xscale:
519 if self.xscale:
@@ -606,15 +605,13 class Plot(Operation):
606 fig.canvas.draw()
605 fig.canvas.draw()
607 if self.show:
606 if self.show:
608 fig.show()
607 fig.show()
609 figpause(0.1)
608 # figpause(0.1)
610
609
611 if self.save:
610 if self.save:
612 self.save_figure(n)
611 self.save_figure(n)
613
612
614 if self.plot_server:
613 if self.plot_server:
615 self.send_to_server()
614 self.send_to_server()
616 # t = Thread(target=self.send_to_server)
617 # t.start()
618
615
619 def save_figure(self, n):
616 def save_figure(self, n):
620 '''
617 '''
@@ -736,10 +733,8 class Plot(Operation):
736
733
737 if self.isConfig is False:
734 if self.isConfig is False:
738 self.__setup(**kwargs)
735 self.__setup(**kwargs)
739 if dataOut.type == 'Parameters':
736
740 t = dataOut.utctimeInit
737 t = getattr(dataOut, self.attr_time)
741 else:
742 t = dataOut.utctime
743
738
744 if dataOut.useLocalTime:
739 if dataOut.useLocalTime:
745 self.getDateTime = datetime.datetime.fromtimestamp
740 self.getDateTime = datetime.datetime.fromtimestamp
@@ -753,10 +748,11 class Plot(Operation):
753 if 'buffer' in self.plot_type:
748 if 'buffer' in self.plot_type:
754 if self.xmin is None:
749 if self.xmin is None:
755 self.tmin = t
750 self.tmin = t
751 self.xmin = self.getDateTime(t).hour
756 else:
752 else:
757 self.tmin = (
753 self.tmin = (
758 self.getDateTime(t).replace(
754 self.getDateTime(t).replace(
759 hour=self.xmin,
755 hour=int(self.xmin),
760 minute=0,
756 minute=0,
761 second=0) - self.getDateTime(0)).total_seconds()
757 second=0) - self.getDateTime(0)).total_seconds()
762
758
@@ -769,16 +765,13 class Plot(Operation):
769 self.poll = zmq.Poller()
765 self.poll = zmq.Poller()
770 self.poll.register(self.socket, zmq.POLLIN)
766 self.poll.register(self.socket, zmq.POLLIN)
771
767
772 if dataOut.type == 'Parameters':
768 tm = getattr(dataOut, self.attr_time)
773 tm = dataOut.utctimeInit
774 else:
775 tm = dataOut.utctime
776
769
777 if not dataOut.useLocalTime and self.localtime:
770 if not dataOut.useLocalTime and self.localtime:
778 tm -= time.timezone
771 tm -= time.timezone
779 if dataOut.useLocalTime and not self.localtime:
772 if dataOut.useLocalTime and not self.localtime:
780 tm += time.timezone
773 tm += time.timezone
781
774
782 if self.xaxis is 'time' and self.data and (tm - self.tmin) >= self.xrange*60*60:
775 if self.xaxis is 'time' and self.data and (tm - self.tmin) >= self.xrange*60*60:
783 self.save_counter = self.save_period
776 self.save_counter = self.save_period
784 self.__plot()
777 self.__plot()
General Comments 0
You need to be logged in to leave comments. Login now