def draw(self, name=None, old=None, new=None):
     if name is not None and self.DONT_DRAW.match(name):
         return
     
     if self._FREEZE:
         return
     
     plot_and_message = ''
     
     # Better way would be a decorator or something that only goes into draw if not autoupdate
     if self.autoupdate:
         
         # Generate new figure object
         f = plt.figure(figsize=(self.figwidth, self.figheight))
         if PLOTPARSER.is_3d(self.kind):
             projection = '3d'
         else:
             projection = None
         ax = f.add_subplot(111, projection=projection)
         
         if self._color_state or self.kind not in ['spec', 'waterfall', 'contour', 'contour3d']:
             colorkwags = dict(color=self.color)
         else:
             colorkwags = dict(cmap=self.colormap, cbar=self.colorbar)
         
         self.spec_modified.plot(ax=ax,
                                 fig=f,
                                 kind=self.kind,
                                 norm=self.NORMUNITS_REV[self.norm_unit],
                                 **colorkwags
                                 )
         f.tight_layout() #Padding around plot
         lines = ax.get_lines()
         plt.close(f)
                                 
         #http://mpld3.github.io/modules/API.html
         if self.interactive:
             import mpld3
             if self.selectlines:
                 from line_plugin import HighlightLines
                 
                 for idx, col in enumerate(self.spec_modified.columns):
                     name = 'COLUMN(%s): %s' % (idx, col)
                     tooltip = mpld3.plugins.LineLabelTooltip(lines[idx], name)
                     #voffset=10, hoffset=10,  css=css)
                     mpld3.plugins.connect(f, tooltip)
                 
                 mpld3.plugins.connect(f, HighlightLines(lines))
             
             plot_and_message += mpld3.fig_to_html(f)
         else:
             plot_and_message += mpl2html(f)
         
         self.fig_old = f
     
     else:
         plot_and_message += html_figure(self.fig_old)
     
     # VALUE IS WHAT GUI LOOKS UP!!!
     self.value = plot_and_message
Example #2
0
 def fig2(self):
     """ Should return out correlation plot, for now just return 
     random html.
     """
     f = plt.figure(figsize=(self.figwidth, self.figheight))
     plt.plot([1,2,3], color=self.color)
     plt.title(self.title)
     return mpl2html(f)
Example #3
0
    def draw(self, name=None, old=None, new=None):
        if name is not None and self.DONT_DRAW.match(name):
            return

        if self._FREEZE:
            return

        plot_and_message = ''

        # Better way would be a decorator or something that only goes into draw if not autoupdate
        if self.autoupdate:

            # Generate new figure object
            f = plt.figure(figsize=(self.figwidth, self.figheight))
            if PLOTPARSER.is_3d(self.kind):
                projection = '3d'
            else:
                projection = None
            ax = f.add_subplot(111, projection=projection)

            if self._color_state or self.kind not in [
                    'spec', 'waterfall', 'contour', 'contour3d'
            ]:
                colorkwags = dict(color=self.color)
            else:
                colorkwags = dict(cmap=self.colormap, cbar=self.colorbar)

            self.spec_modified.plot(ax=ax,
                                    fig=f,
                                    kind=self.kind,
                                    norm=self.NORMUNITS_REV[self.norm_unit],
                                    **colorkwags)
            f.tight_layout()  #Padding around plot
            lines = ax.get_lines()
            plt.close(f)

            #http://mpld3.github.io/modules/API.html
            if self.interactive:
                import mpld3
                if self.selectlines:
                    from line_plugin import HighlightLines

                    for idx, col in enumerate(self.spec_modified.columns):
                        name = 'COLUMN(%s): %s' % (idx, col)
                        tooltip = mpld3.plugins.LineLabelTooltip(
                            lines[idx], name)
                        #voffset=10, hoffset=10,  css=css)
                        mpld3.plugins.connect(f, tooltip)

                    mpld3.plugins.connect(f, HighlightLines(lines))

                plot_and_message += mpld3.fig_to_html(f)
            else:
                plot_and_message += mpl2html(f)

            self.fig_old = f

        else:
            plot_and_message += html_figure(self.fig_old)

        # VALUE IS WHAT GUI LOOKS UP!!!
        self.value = plot_and_message
Example #4
0
    def draw(self, name=None, old=None, new=None):
        if name is not None and self.DONT_DRAW.match(name):
            return

        if self._FREEZE:
            return

        plot_and_message = ''

        # Better way would be a decorator or something that only goes into draw if not autoupdate
        if self.autoupdate:

            # Generate new figure object
            f = plt.figure(figsize=(self.figwidth, self.figheight))
            if self.plot3d in ['corr3d', 'contour3d']:
                projection = '3d'
            else:
                projection = None
            ax = f.add_subplot(111, projection=projection)

            ### UNCOMMENT ME FOR IMAGE
            #from skimage import data
            #from image_inspector.linetool import ThickLineTool

            #image = data.camera()

            #f, ax = plt.subplots()
            #ax.imshow(image, interpolation='nearest')
            #h, w = image.shape

            #def roi_changed(roi):
            #print(roi.shape, roi.geometry, roi.data.shape)

            ## line_tool = LineTool(ax)
            #line_tool = ThickLineTool(ax)
            #line_tool.connect_event('roi_changed', roi_changed)
            #line_tool.end_points = ([w/3, h/2], [2*w/3, h/2])

            if self._color_state or self.kind not in [
                    'spec', 'waterfall', 'contour', 'contour3d'
            ]:
                colorkwags = dict(color=self.color)
            else:
                colorkwags = dict(cmap=self.colormap, cbar=self.colorbar)

            #self.spec_modified.plot(ax=ax,
            #fig=f,
            #kind=self.kind,
            #norm=self.NORMUNITS_REV[self.norm_unit],
            #**colorkwags
            #)
            f.tight_layout()  #Padding around plot
            lines = ax.get_lines()

            #aka async.plot(kind='contour3d')
            pltkwds = dict(kind=self.plot3d, fill=self.fill, fig=f)
            pltkwds.update(colorkwags)

            # 3d correlation plots need an axes, but 2d plots don't because a 2d corr
            # plot is really 4 axes together...
            if projection == '3d':
                pltkwds['ax'] = ax
                #       pltkwds['elev'] = 100
                #       pltkwds['azim'] = 99
                #       pltkwds['projection'] = 'xz'  #xy, xz, zy, yx, zx, yz
                # Corr3d has special arguments called contourkwds (PROOF OF CONCEPT)
                pltkwds['contourkwargs'] = dict(fill=self.fill)

            getattr(self.corr2d, self.plottype).plot(**pltkwds)

            plt.close(f)

            #http://mpld3.github.io/modules/API.html
            if self.interactive:
                import mpld3
                if self.selectlines:
                    from line_plugin import HighlightLines

                    for idx, col in enumerate(self.spec_modified.columns):
                        name = 'COLUMN(%s): %s' % (idx, col)
                        tooltip = mpld3.plugins.LineLabelTooltip(
                            lines[idx], name)
                        #voffset=10, hoffset=10,  css=css)
                        mpld3.plugins.connect(f, tooltip)

                    mpld3.plugins.connect(f, HighlightLines(lines))

                plot_and_message += mpld3.fig_to_html(f)
            else:
                plot_and_message += mpl2html(f)

            self.fig_old = f

        else:
            plot_and_message += html_figure(self.fig_old)

        # VALUE IS WHAT GUI LOOKS UP!!!
        self.value = plot_and_message


### TO FIX ###
# When change normunit and slice, spec_modified does't update normunit, iunit, varunit
# 3D plot is not drawing, we think it is a bug
    def draw(self, name=None, old=None, new=None):
            if name is not None and self.DONT_DRAW.match(name):
                return
            
            if self._FREEZE:
                return
            
            plot_and_message = ''
            
            # Better way would be a decorator or something that only goes into draw if not autoupdate
            if self.autoupdate:
                
                # Generate new figure object
                f = plt.figure(figsize=(self.figwidth, self.figheight))
                if self.plot3d in ['corr3d', 'contour3d']:
                    projection = '3d'
                else:
                    projection = None
                ax = f.add_subplot(111, projection=projection)
                
                ### UNCOMMENT ME FOR IMAGE
                #from skimage import data
                #from image_inspector.linetool import ThickLineTool
                
                
                #image = data.camera()
            
                #f, ax = plt.subplots()
                #ax.imshow(image, interpolation='nearest')
                #h, w = image.shape
            
                #def roi_changed(roi):
                    #print(roi.shape, roi.geometry, roi.data.shape)
        
                ## line_tool = LineTool(ax)
                #line_tool = ThickLineTool(ax)
                #line_tool.connect_event('roi_changed', roi_changed)
                #line_tool.end_points = ([w/3, h/2], [2*w/3, h/2])                              
                
                if self._color_state or self.kind not in ['spec', 'waterfall', 'contour', 'contour3d']:
                    colorkwags = dict(color=self.color)
                else:
                    colorkwags = dict(cmap=self.colormap, cbar=self.colorbar)
                
                #self.spec_modified.plot(ax=ax,
                                        #fig=f,
                                        #kind=self.kind,
                                        #norm=self.NORMUNITS_REV[self.norm_unit],
                                        #**colorkwags
                                        #)
                f.tight_layout() #Padding around plot
                lines = ax.get_lines()
                
                #aka async.plot(kind='contour3d')
                pltkwds =dict(kind=self.plot3d,
                              fill=self.fill,
                              fig=f)
                pltkwds.update(colorkwags)
                
                # 3d correlation plots need an axes, but 2d plots don't because a 2d corr
                # plot is really 4 axes together...
                if projection == '3d':
                    pltkwds['ax'] = ax
             #       pltkwds['elev'] = 100
             #       pltkwds['azim'] = 99
             #       pltkwds['projection'] = 'xz'  #xy, xz, zy, yx, zx, yz
                    # Corr3d has special arguments called contourkwds (PROOF OF CONCEPT)
                    pltkwds['contourkwargs'] = dict(fill=self.fill)
                
                getattr(self.corr2d, self.plottype).plot(**pltkwds)
                    
                plt.close(f)
                                        
                #http://mpld3.github.io/modules/API.html
                if self.interactive:
                    import mpld3
                    if self.selectlines:
                        from line_plugin import HighlightLines
                        
                        for idx, col in enumerate(self.spec_modified.columns):
                            name = 'COLUMN(%s): %s' % (idx, col)
                            tooltip = mpld3.plugins.LineLabelTooltip(lines[idx], name)
                            #voffset=10, hoffset=10,  css=css)
                            mpld3.plugins.connect(f, tooltip)
                        
                        mpld3.plugins.connect(f, HighlightLines(lines))
                    
                    plot_and_message += mpld3.fig_to_html(f)
                else:
                    plot_and_message += mpl2html(f)
                
                self.fig_old = f
            
            else:
                plot_and_message += html_figure(self.fig_old)
            
            # VALUE IS WHAT GUI LOOKS UP!!!
            self.value = plot_and_message
            
            
### TO FIX ###
# When change normunit and slice, spec_modified does't update normunit, iunit, varunit
# 3D plot is not drawing, we think it is a bug