Example #1
0
    def generate_artist(self):
           container=self.get_container()
           if self.isempty() is False:
               return

           x, y = self._eval_xy() # this handles "use_var"
 
           lp=self.getp("loaded_property") 

           if True:
              x, y = self.getp(("x", "y"))
              if y is None: return
              if x is None: return 
              
              if (x is not None  and
                  y is not None):   
                  self._data_extent=[np.nanmin(x), np.nanmax(x), 
                                     np.nanmin(y), np.nanmax(y)]

                  if len(y.shape) == 1:
                     kywds = self._var["kywds"]
                     args, self._tri =  tri_args(x, y, self._tri) 
                     kywds['mask'] = self.getp('mask')
                     kywds['linestyle'] = self.getp('linestyle')
                     kywds['linewidth'] = self.getp('linewidth')
                     kywds['color'] = self.getp('color')
                     a =  triplot(container, *args, **kywds)
                     self.set_artist(a[0])
                     self._other_artists = a[1:]

           if lp is not None:
              for i in range(0, len(lp)):
                  self.set_artist_property(self._artists[i], lp[i])
              self.delp("loaded_property")
           self.set_rasterized()
Example #2
0
    def generate_artist(self):
        container = self.get_container()
        if self.isempty() is False:
            return

        x, y = self._eval_xy()  # this handles "use_var"

        lp = self.getp("loaded_property")

        if True:
            x, y = self.getp(("x", "y"))
            if y is None:
                return
            if x is None:
                return

            if (x is not None and y is not None):
                self._data_extent = [
                    np.nanmin(x),
                    np.nanmax(x),
                    np.nanmin(y),
                    np.nanmax(y)
                ]

                if len(y.shape) == 1:
                    kywds = self._var["kywds"]
                    args, self._tri = tri_args(x, y, self._tri)
                    kywds['mask'] = self.getp('mask')
                    kywds['linestyle'] = self.getp('linestyle')
                    kywds['linewidth'] = self.getp('linewidth')
                    kywds['color'] = self.getp('color')
                    a = triplot(container, *args, **kywds)
                    self.set_artist(a[0])
                    self._other_artists = a[1:]

        if lp is not None:
            for i in range(0, len(lp)):
                self.set_artist_property(self._artists[i], lp[i])
            self.delp("loaded_property")
        self.set_rasterized()
Example #3
0
    def generate_artist(self):
        ### this method generate artist
        ### if artist does exist, update artist
        ### based on the information specifically
        ### managed by fig_obj tree. Any property 
        ### internally managed by matplotlib 
        ### does not change
           container=self.get_container()
           if container is None: return

           flag = 0
           if self.isempty() is False:
              return
           x, y, z = self._eval_xyz() # this handles "use_var"
           if z is None: return
        
           lp=self.getp("loaded_property") 

           v, n, FillMode = self.getp(('v', 'n', 'FillMode'))

           kywds = self.getvar('kywds')
           kywds['alpha'] = self.getp('alpha')


           if self.getp('use_tri'):
               x = x.flatten()
               y = y.flatten()
               z = z.flatten()                              
               args, self._tri =  tri_args(x, y, self._tri)
               print args
           else:
               args=[]               
               if x is not None: args.append(x)
               if y is not None: args.append(y)
               if z is not None: args.append(z)
           if (not self._nouse_expression and
               v is not None):
               args.append(v)
           else:
               args.append(int(n))

           cax = self.get_caxisparam()

#           dprint2(args)              
           if len(args) == 0: return

           self._data_extent=[np.min(x), np.max(x), np.min(y), np.max(y)]
#           self.setp("data_extent",[min(x), max(x), min(y), max(y)])
           try:
               if self.get_figaxes().get_3d(): 
                   kywds['offset'] = self.getvar('offset')
                   kywds['zdir'] = self.getvar('zdir')
           except:
               pass
           if self.getp('use_tri'):
               if FillMode:
                    method = container.tricontourf
               else:
                    method = container.tricontour
           else:
               if FillMode:               
                   method = container.contourf
               else:
                   method = container.contour
           try:
              self._mappable = method(*args, **kywds)
              self._artists = self._mappable.collections[:]
              self.set_rasterized()
              for a in self.get_mappable():
                  cax.set_crangeparam_to_artist(a)
           except Exception:
              logging.exception("FigContour:generate_artist : artist generation failed")

           if lp is not None:
#              print lp
              for i, var in enumerate(lp):
                  if len(self._artists) > i:
                       self.set_artist_property(self._artists[i], var)
              self.delp("loaded_property")

           for path in self._artists:
#                 path.set_picker(cpicker.Picker)
                 path.figobj=self
                 path.figobj_hl=[]
                 path.set_zorder(self.getp('zorder'))

           if self._clabel_param['use_clabel'] and not FillMode:
               args, kargs = self._make_clabel_param()
               wx.CallLater(1, self.call_clabel, *args, **kargs)
Example #4
0
    def generate_artist(self):
        ### this method generate artist
        ### if artist does exist, update artist
        ### based on the information specifically
        ### managed by fig_obj tree. Any property
        ### internally managed by matplotlib
        ### does not change
        container = self.get_container()
        if container is None: return

        flag = 0
        if self.isempty() is False:
            return
        x, y, z = self._eval_xyz()  # this handles "use_var"
        if z is None: return

        lp = self.getp("loaded_property")

        v, n, FillMode = self.getp(('v', 'n', 'FillMode'))

        kywds = self.getvar('kywds')
        kywds['alpha'] = self.getp('alpha')

        if self.getp('use_tri'):
            x = x.flatten()
            y = y.flatten()
            z = z.flatten()
            args, self._tri = tri_args(x, y, self._tri)
            print args
        else:
            args = []
            if x is not None: args.append(x)
            if y is not None: args.append(y)
            if z is not None: args.append(z)
        if (not self._nouse_expression and v is not None):
            args.append(v)
        else:
            args.append(int(n))

        cax = self.get_caxisparam()

        #           dprint2(args)
        if len(args) == 0: return

        self._data_extent = [np.min(x), np.max(x), np.min(y), np.max(y)]
        #           self.setp("data_extent",[min(x), max(x), min(y), max(y)])
        try:
            if self.get_figaxes().get_3d():
                kywds['offset'] = self.getvar('offset')
                kywds['zdir'] = self.getvar('zdir')
        except:
            pass
        if self.getp('use_tri'):
            if FillMode:
                method = container.tricontourf
            else:
                method = container.tricontour
        else:
            if FillMode:
                method = container.contourf
            else:
                method = container.contour
        try:
            self._mappable = method(*args, **kywds)
            self._artists = self._mappable.collections[:]
            self.set_rasterized()
            for a in self.get_mappable():
                cax.set_crangeparam_to_artist(a)
        except Exception:
            logging.exception(
                "FigContour:generate_artist : artist generation failed")

        if lp is not None:
            #              print lp
            for i, var in enumerate(lp):
                if len(self._artists) > i:
                    self.set_artist_property(self._artists[i], var)
            self.delp("loaded_property")

        for path in self._artists:
            #                 path.set_picker(cpicker.Picker)
            path.figobj = self
            path.figobj_hl = []
            path.set_zorder(self.getp('zorder'))

        if self._clabel_param['use_clabel'] and not FillMode:
            args, kargs = self._make_clabel_param()
            wx.CallLater(1, self.call_clabel, *args, **kargs)
Example #5
0
    def generate_artist(self):
        ### this method generate artist
        ### if artist does exist, update artist
        ### based on the information specifically
        ### managed by fig_obj tree. Any property
        ### internally managed by matplotlib
        ### does not change
        container = self.get_container()
        if container is None: return
        #           if self.get_figaxes().get_3d(): return
        if self.isempty() is False:
            return
        x, y, z = self._eval_xyz()
        if z is None: return

        lp = self.getp("loaded_property")
        aspect = container.get_aspect()
        cax = self.get_caxisparam()
        if cax is None:
            dprint1('Error: cax is None')
            return
        crange = cax.range

        if lp is None or len(lp) == 0:
            if (self._tri is not None and self._tri.shape[0] == z.size):
                pass

            else:
                if (x.size * y.size != z.size
                        and not (x.size == z.size and y.size == z.size)):
                    print('FigImage: array size is wrong')
                    return

            if not self.getvar('use_tri'):
                if self.get_figaxes().get_3d():
                    xp, yp, zp = x, y, z
                    extent = (
                        np.min(x),
                        np.max(x),
                        np.min(y),
                        np.max(y),
                    )
                else:
                    xp, yp, zp = self.interp_image(x, y, z)
                    extent = (
                        np.min(xp),
                        np.max(xp),
                        np.min(yp),
                        np.max(yp),
                    )
                args = []
                kywds = self._var["kywds"]
                kywds['alpha'] = self.getp('alpha')
                #              args.append(np.flipud(zp))

                if cax.scale == 'linear':
                    args.append(zp)
                    kywds["vmin"] = crange[0]
                    kywds["vmax"] = crange[1]
                else:
                    # args.append(np.log10(zp))
                    args.append(zp)
                    kywds["vmin"] = np.log10(max((crange[0], 1e-16)))
                    kywds["vmax"] = np.log10(max((crange[1], 1e-16)))

                kywds["aspect"] = aspect
                kywds["origin"] = 'lower'
                kywds["interpolation"] = self.getp("interp")
                self.set_artist(
                    container.imshow(
                        *args,
                        #                            picker=cpicker.Picker,
                        extent=extent,
                        **kywds))
                cax.set_crangeparam_to_artist(self._artists[0])
                setattr(self._artists[0].get_array(), '_xyp', (xp, yp))
            else:
                #print('drawing tri image')
                if x.size * y.size == z.size:
                    X, Y = np.meshgrid(x, y)
                    x = X.flatten()
                    y = Y.flatten()
                else:
                    if len(x.shape) != 1: x = x.flatten()
                    if len(y.shape) != 1: y = y.flatten()
                args, self._tri = tri_args(x, y, self._tri)
                kywds = self._var["kywds"]
                kywds['alpha'] = self.getp('alpha')
                if cax.scale == 'linear':
                    args.append(z.flatten().astype(float))
                    kywds["clim"] = (crange[0], crange[1])
                else:
                    # args.append(np.log10(z))
                    args.append(z.flatten().astype(float))
                    kywds["clim"] = [
                        np.log10(max((crange[0], 1e-16))),
                        np.log10(max((crange[1], 1e-16)))
                    ]
                kywds['shading'] = self.getp('shading')
                kywds['mask'] = self.getp('mask')
                self.set_artist(container.tripcolor(*args, **kywds))
                cax.set_crangeparam_to_artist(self._artists[0])
            self._data_extent = [np.min(x), np.max(x), np.min(y), np.max(y)]
        else:
            if self.getvar('use_tri'):
                #print('redrawing tri image')
                x, y, z = self.getp(('x', 'y', 'z'))
                x = x.flatten()
                y = y.flatten()
                args, self._tri = tri_args(x, y, self._tri)

                args.append(z.flatten().astype(float))
                # astype(float) is patch work to open past files..

                kywds = self._var["kywds"]
                kywds = lp[0]
                kywds['shading'] = self.getp('shading')
                kywds['mask'] = self.getp('mask')
                kywds['alpha'] = self.getp('alpha')
                keys = ['alpha', 'cmap', 'zorder']
                for k in keys:
                    if k in lp[0]: kywds[k] = lp[0][k]
#                  print lp
#                  kywds["clim"]=lp[0]["clim"]
                self.set_artist(container.tripcolor(*args, **kywds))
                cax.set_crangeparam_to_artist(self._artists[0])

            else:
                x, y, z = self.getp(('x', 'y', 'z'))
                xp, yp, zp = self.interp_image(x, y, z)
                args = []
                kywds = {}
                kywds['alpha'] = self.getp('alpha')
                kywds["interpolation"] = self.getp("interp")
                #                  print lp[0]
                if cax.scale == 'linear':
                    args.append(zp)
                    kywds["vmin"] = crange[0]
                    kywds["vmax"] = crange[1]
                else:
                    args.append(zp)
                    kywds["vmin"] = np.log10(max((crange[0], 1e-16)))
                    kywds["vmax"] = np.log10(max((crange[1], 1e-16)))
                keys = ['alpha', 'cmap', 'zorder']
                for k in keys:
                    if k in lp[0]: kywds[k] = lp[0][k]
                self.set_artist(
                    container.imshow(*args,
                                     extent=lp[0]["extent"],
                                     aspect=aspect,
                                     origin='lower',
                                     **kywds))
                cax.set_crangeparam_to_artist(self._artists[0])
                setattr(self._artists[0].get_array(), '_xyp', (xp, yp))
        self.delp("loaded_property")

        self.set_rasterized()
        # this is to resize image when window is resized...
        if not self._cb_added:
            fig_page = self.get_figpage()
            fig_page.add_resize_cb(self)
            self._cb_added = True
Example #6
0
    def generate_artist(self):
        ### this method generate artist
        ### if artist does exist, update artist
        ### based on the information specifically
        ### managed by fig_obj tree. Any property 
        ### internally managed by matplotlib 
        ### does not change
           container=self.get_container()
           if container is None: return
#           if self.get_figaxes().get_3d(): return
           if self.isempty() is False:
               return
           x, y, z = self._eval_xyz()
           if z is None: return

           lp=self.getp("loaded_property")
           aspect = container.get_aspect()
           cax = self.get_caxisparam()
           if cax is None:
               dprint1('Error: cax is None')
               return
           crange = cax.range

           if lp is None or len(lp) == 0:
              if (self._tri is not None and
                  self._tri.shape[0] == z.size):
                  pass

              else:
                  if (x.size*y.size != z.size and
                      not (x.size == z.size and y.size==z.size)):
                      print('FigImage: array size is wrong')
                      return 

              if not self.getvar('use_tri'):
                  if self.get_figaxes().get_3d():
                      xp, yp, zp = x, y, z
                      extent = (np.min(x), np.max(x), 
                                np.min(y), np.max(y), )
                  else:
                      xp, yp, zp = self.interp_image(x, y, z)
                      extent = (np.min(xp), np.max(xp), 
                                np.min(yp), np.max(yp), )
                  args=[]
                  kywds=self._var["kywds"]
                  kywds['alpha'] = self.getp('alpha')
    #              args.append(np.flipud(zp))

                  if cax.scale == 'linear':
                      args.append(zp)
                      kywds["vmin"]=crange[0]
                      kywds["vmax"]=crange[1]
                  else:
                      # args.append(np.log10(zp))
                      args.append(zp)                      
                      kywds["vmin"]=np.log10(max((crange[0], 1e-16)))
                      kywds["vmax"]=np.log10(max((crange[1], 1e-16)))

                  kywds["aspect"]=aspect
                  kywds["origin"]='lower'
                  kywds["interpolation"]=self.getp("interp")        
                  self.set_artist(container.imshow(*args, 
    #                            picker=cpicker.Picker,
                                   extent=extent,  **kywds))
                  cax.set_crangeparam_to_artist(self._artists[0])
                  setattr(self._artists[0].get_array(), '_xyp', (xp, yp))
              else:
                  #print('drawing tri image')
                  if x.size*y.size == z.size:
                     X, Y = np.meshgrid(x, y)
                     x = X.flatten()
                     y = Y.flatten()
                  else:
                     if len(x.shape) != 1: x = x.flatten()
                     if len(y.shape) != 1: y = y.flatten()
                  args, self._tri =  tri_args(x, y, self._tri)
                  kywds=self._var["kywds"]
                  kywds['alpha'] = self.getp('alpha')
                  if cax.scale == 'linear':
                      args.append(z.flatten().astype(float)) 
                      kywds["clim"]=(crange[0], crange[1])
                  else:
                      # args.append(np.log10(z))
                      args.append(z.flatten().astype(float))                       
                      kywds["clim"]=[np.log10(max((crange[0], 1e-16))),
                                     np.log10(max((crange[1], 1e-16)))]
                  kywds['shading']=self.getp('shading')
                  kywds['mask']=self.getp('mask')
                  self.set_artist(container.tripcolor(*args,
                                   **kywds))
                  cax.set_crangeparam_to_artist(self._artists[0])
              self._data_extent = [np.min(x), np.max(x), 
                                   np.min(y), np.max(y)]
           else:
              if self.getvar('use_tri'):
                  #print('redrawing tri image')
                  x, y, z = self.getp(('x', 'y', 'z'))
                  x = x.flatten()
                  y = y.flatten()
                  args, self._tri =  tri_args(x, y, self._tri)

                  args.append(z.flatten().astype(float))
                  # astype(float) is patch work to open past files..

                  kywds=self._var["kywds"]
                  kywds = lp[0]
                  kywds['shading']=self.getp('shading')
                  kywds['mask'] = self.getp('mask')
                  kywds['alpha'] = self.getp('alpha')
                  keys = ['alpha', 'cmap', 'zorder']
                  for k in keys:
                      if k in lp[0]: kywds[k]  = lp[0][k]
#                  print lp
#                  kywds["clim"]=lp[0]["clim"] 
                  self.set_artist( container.tripcolor(*args,
                                   **kywds))
                  cax.set_crangeparam_to_artist(self._artists[0])

              else:
                  x, y, z = self.getp(('x', 'y', 'z'))
                  xp, yp, zp = self.interp_image(x, y, z)
                  args=[]
                  kywds = {}
                  kywds['alpha'] = self.getp('alpha')
                  kywds["interpolation"]=self.getp("interp")                          
#                  print lp[0]
                  if cax.scale == 'linear':
                      args.append(zp)                      
                      kywds["vmin"]=crange[0]
                      kywds["vmax"]=crange[1]
                  else:
                      args.append(zp)                      
                      kywds["vmin"]=np.log10(max((crange[0], 1e-16)))
                      kywds["vmax"]=np.log10(max((crange[1], 1e-16)))
                  keys = ['alpha', 'cmap', 'zorder']
                  for k in keys:
                      if k in lp[0]: kywds[k]  = lp[0][k]
                  self.set_artist(container.imshow(*args, 
                               extent = lp[0]["extent"], aspect=aspect,
                               origin='lower', **kywds))
                  cax.set_crangeparam_to_artist(self._artists[0])
                  setattr(self._artists[0].get_array(), '_xyp', (xp, yp))
           self.delp("loaded_property")
           
           self.set_rasterized()
           # this is to resize image when window is resized...
           if not self._cb_added:
               fig_page = self.get_figpage()
               fig_page.add_resize_cb(self)
               self._cb_added = True