当前位置: 首页>>代码示例>>Python>>正文


Python LinearSegmentedColormap.set_over方法代码示例

本文整理汇总了Python中matplotlib.colors.LinearSegmentedColormap.set_over方法的典型用法代码示例。如果您正苦于以下问题:Python LinearSegmentedColormap.set_over方法的具体用法?Python LinearSegmentedColormap.set_over怎么用?Python LinearSegmentedColormap.set_over使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.colors.LinearSegmentedColormap的用法示例。


在下文中一共展示了LinearSegmentedColormap.set_over方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _register_cmap_clip

# 需要导入模块: from matplotlib.colors import LinearSegmentedColormap [as 别名]
# 或者: from matplotlib.colors.LinearSegmentedColormap import set_over [as 别名]
def _register_cmap_clip(name, original_cmap, alpha):
    """Create a color map with "over" and "under" values."""
    from matplotlib.colors import LinearSegmentedColormap
    cdata = _plt.cm.datad[original_cmap]
    if isinstance(cdata, dict):
        cmap = LinearSegmentedColormap(name, cdata)
    else:
        cmap = LinearSegmentedColormap.from_list(name, cdata)
    cmap.set_over([alpha * c + 1 - alpha for c in cmap(1.0)[:3]])
    cmap.set_under([alpha * c + 1 - alpha for c in cmap(0.0)[:3]])
    _plt.cm.register_cmap(cmap=cmap)
开发者ID:sfstoolbox,项目名称:sfs-python,代码行数:13,代码来源:plot2d.py

示例2: build_cmap

# 需要导入模块: from matplotlib.colors import LinearSegmentedColormap [as 别名]
# 或者: from matplotlib.colors.LinearSegmentedColormap import set_over [as 别名]
def build_cmap(stops): 
# {{{
  from matplotlib.colors import LinearSegmentedColormap
  ct = dict(red=[], blue=[], green=[])
  for s in stops:
    if 'r2' in s:
      ct['red'].append((s['s'], s['r'], s['r2']))
      ct['green'].append((s['s'], s['g'], s['g2']))
      ct['blue'].append((s['s'], s['b'], s['b2']))
    else:
      ct['red'].append((s['s'], s['r'], s['r']))
      ct['green'].append((s['s'], s['g'], s['g']))
      ct['blue'].append((s['s'], s['b'], s['b']))
  cm = LinearSegmentedColormap('loaded_colourmap', ct, 256)
  cm.set_under((stops[ 0]['r'], stops[ 0]['g'], stops[ 0]['b']))
  cm.set_over ((stops[-1]['r'], stops[-1]['g'], stops[-1]['b']))
  return cm
开发者ID:neishm,项目名称:pygeode,代码行数:19,代码来源:cm.py

示例3: _shiftedColorMap

# 需要导入模块: from matplotlib.colors import LinearSegmentedColormap [as 别名]
# 或者: from matplotlib.colors.LinearSegmentedColormap import set_over [as 别名]
    def _shiftedColorMap(self, cmap, start=0, midpoint=0.5, stop=1.0,
                         name='shiftedcmap'):
        '''
        Taken from

        https://github.com/olgabot/prettyplotlib/blob/master/prettyplotlib/colors.py

        which makes beautiful plots by the way


        Function to offset the "center" of a colormap. Useful for
        data with a negative min and positive max and you want the
        middle of the colormap's dynamic range to be at zero

        Input
        -----
          cmap : The matplotlib colormap to be altered
          start : Offset from lowest point in the colormap's range.
              Defaults to 0.0 (no lower ofset). Should be between
              0.0 and `midpoint`.
          midpoint : The new center of the colormap. Defaults to
              0.5 (no shift). Should be between 0.0 and 1.0. In
              general, this should be  1 - vmax/(vmax + abs(vmin))
              For example if your data range from -15.0 to +5.0 and
              you want the center of the colormap at 0.0, `midpoint`
              should be set to  1 - 5/(5 + 15)) or 0.75
          stop : Offset from highets point in the colormap's range.
              Defaults to 1.0 (no upper ofset). Should be between
              `midpoint` and 1.0.
        '''
        import matplotlib.pyplot as plt
        from matplotlib.colors import LinearSegmentedColormap
        cdict = {
            'red': [],
            'green': [],
            'blue': [],
            'alpha': []
        }

        # regular index to compute the colors
        reg_index = np.linspace(start, stop, 257)

        # shifted index to match the data
        shift_index = np.hstack([
            np.linspace(0.0, midpoint, 128, endpoint=False),
            np.linspace(midpoint, 1.0, 129, endpoint=True)
        ])

        for ri, si in zip(reg_index, shift_index):
            r, g, b, a = cmap(ri)

            cdict['red'].append((si, r, r))
            cdict['green'].append((si, g, g))
            cdict['blue'].append((si, b, b))
            cdict['alpha'].append((si, a, a))

        newcmap = LinearSegmentedColormap(name, cdict)

        # add some overunders
        newcmap.set_bad(color='g', alpha=0.75)
        newcmap.set_over(color='m', alpha=0.75)
        newcmap.set_under(color='c', alpha=0.75)

        plt.register_cmap(cmap=newcmap)

        return newcmap
开发者ID:cpadavis,项目名称:LearnPSF,代码行数:68,代码来源:zernike.py

示例4: LinearSegmentedColormap

# 需要导入模块: from matplotlib.colors import LinearSegmentedColormap [as 别名]
# 或者: from matplotlib.colors.LinearSegmentedColormap import set_over [as 别名]
(0.968627450980392,0.78075390625,0.78075390625),
(0.972549019607843,0.79254296875,0.79254296875),
(0.976470588235294,0.80433203125,0.80433203125),
(0.980392156862745,0.81612109375,0.81612109375),
(0.984313725490196,0.82791015625,0.82791015625),
(0.988235294117647,0.839703125,0.839703125),
(0.992156862745098,0.8514921875,0.8514921875),
(0.996078431372549,0.86328125,0.86328125),
(1,0,0)),
 }


califa = LinearSegmentedColormap('CALIFA', cdict)
califa.set_bad(color='navy')
califa.set_under(color='navy')
califa.set_over(color='navy')
register_cmap(cmap=califa)




#plt.xkcd()
hdus = fits.open('NGC4047.p_e.rad_SFR_lum_Mass.fits.gz')
img = hdus[0].data
fig=plt.figure()
ax1 = fig.add_subplot(111)
#img_mask= np.power(10, img)
img_masked= img
where_are_NaNs = np.isnan(img_masked)
img_masked[where_are_NaNs] = 0
ticksy=np.linspace(0,2,9)
开发者ID:calibosbar,项目名称:calibosbar.github.com,代码行数:33,代码来源:plot_mgh_final.py

示例5: LinearSegmentedColormap

# 需要导入模块: from matplotlib.colors import LinearSegmentedColormap [as 别名]
# 或者: from matplotlib.colors.LinearSegmentedColormap import set_over [as 别名]
color_dict = {'red':   ((0.00, 0.10, 0.10),
                        (0.33, 0.10, 0.10),
                        (0.67, 1.00, 1.00),
                        (1.00, 1.00, 1.00)),
              'green': ((0.00, 0.10, 0.10),
                        (0.33, 0.10, 0.10),
                        (0.67, 0.50, 0.50),
                        (1.00, 1.00, 1.00)),
              'blue':  ((0.00, 0.10, 0.10),
                        (0.33, 0.50, 0.50),
                        (0.67, 0.10, 0.10),
                        (1.00, 1.00, 1.00))
             }
amber_teal = LinearSegmentedColormap('OrangeTeal1', color_dict)
amber_teal.set_under('#191919')
amber_teal.set_over('#FFFFFF')
colormap = 'jet'

# Constrain the colorbar
P_min  = np.min( P[P>0.].cgs.value )                                                      # Minimum (non-empty) value of sigma
P_max  = np.max( P.cgs.value )                                                            # Maximum value of sigma
levels     = np.linspace( np.floor(np.log10(P_min)), np.ceil(np.log10(P_max)), 100 )      # Levels of colorbar
cbar_ticks = np.arange( np.floor(np.log10(P_min)), np.ceil(np.log10(P_max))+0.1, 0.5 )    # Ticks of colorbar

# Create plot
fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))           # Use polar coordinate system
plt.subplots_adjust(bottom=0.25)                                      # Create space at the bottom for the slider

plot = ax.contourf(theta_cen, R_cen.to(u.AU), np.log10(P[ :, :].cgs.value), cmap=colormap, levels=levels, extend='both' )       # Filled contour plot
collections_list = plot.collections[:]                                                                                            # Collect the collections....lol
#planet, = ax.plot(planet_theta[i_image], planet_R[i_image].to(u.AU), color='cyan', marker='o', markersize=8, markeredgecolor='black') # Cross at planet position
开发者ID:MatiasFloresS,项目名称:CudaProtoplanetaryDisks,代码行数:33,代码来源:Dens.py

示例6: test_problem_16

# 需要导入模块: from matplotlib.colors import LinearSegmentedColormap [as 别名]
# 或者: from matplotlib.colors.LinearSegmentedColormap import set_over [as 别名]
    def test_problem_16(self):
        """
        Schittkowski problem #16
        """
        cost = Problem16_Cost ()
        problem = roboptim.core.PyProblem (cost)
        problem.startingPoint = numpy.array([-2, 1., ])
        problem.argumentBounds = numpy.array([[-2., 0.5],
                                              [-float("inf"), 1.]])

        g1 = Problem16_G1 ()
        problem.addConstraint (g1, [0., float("inf"),])
        g2 = Problem16_G2 ()
        problem.addConstraint (g2, [0., float("inf"),])

        # Check starting value
        numpy.testing.assert_almost_equal (cost (problem.startingPoint)[0], 909.)

        # Initialize callback
        callback = IterCallback (problem)

        # Let the test fail if the solver does not exist.
        try:
            # Create solver
            log_dir = "/tmp/roboptim-core-python/problem_16"
            solver = roboptim.core.PySolver ("ipopt", problem, log_dir = log_dir)

            # Add callback
            solver.addIterationCallback(callback)

            print (solver)
            solver.solve ()
            r = solver.minimum ()
            print (r)

            # Plot results
            plotter = Plotter2D([-2.1,0.6],[0,1.1])
            plotter.x_res = 100
            plotter.y_res = 100
            plotter.plot(cost, plot_style = PlotStyle2D.PColorMesh, vmax=10,
                         norm=LogNorm())

            # Set up a colormap:
            cdict = {'red':   ((0.0, 0.0, 0.0),
                               (1.0, 0.0, 0.0)),

                     'green': ((0.0, 0.0, 0.0),
                               (1.0, 0.0, 0.0)),

                     'blue':  ((0.0, 0.0, 0.0),
                               (1.0, 0.0, 0.0)),

                     'alpha': ((0.0, 0.0, 0.0),
                               (1.0, 1.0, 1.0))
                    }
            cstr_cmap = LinearSegmentedColormap('Mask', cdict)
            cstr_cmap.set_under('r', alpha=0)
            cstr_cmap.set_over('w', alpha=0)
            cstr_cmap.set_bad('g', alpha=0)

            plotter.plot(g1, plot_style=PlotStyle2D.Contourf,
                         linewidth=10, alpha=None,
                         cmap=cstr_cmap, vmax=0, fontsize=20)
            plotter.plot(g1, plot_style=PlotStyle2D.Contour,
                         linewidth=10, alpha=None, levels=[0],
                         vmax=0, fontsize=20, colors="k")
            plotter.plot(g2, plot_style=PlotStyle2D.Contourf,
                         linewidth=10, alpha=None,
                         cmap=cstr_cmap, vmax=0)

            # Print iterations
            X = zip(*callback.x)[0]
            Y = zip(*callback.x)[1]
            # Show evolution
            plotter.add_marker(X, Y,
                               color="white", marker=".", markersize=5)
            # First point
            plotter.add_marker(X[0], Y[0],
                               color="white", marker="o", markersize=10, markeredgewidth=2)
            # Final result
            plotter.add_marker(X[-1], Y[-1],
                               color="white", marker="s", markersize=10, markeredgewidth=2)

            # Print actual global minimum
            plotter.add_marker(0.5, 0.25,
                               color="black", marker="x", markersize=14, markeredgewidth=6)
            plotter.add_marker(0.5, 0.25,
                               color="white", marker="x", markersize=10, markeredgewidth=3)

            plotter.show()

        except Exception as e:
            print ("Error: %s" % e)
开发者ID:francois-keith,项目名称:roboptim-core-python,代码行数:95,代码来源:problem_16.py

示例7: mds

# 需要导入模块: from matplotlib.colors import LinearSegmentedColormap [as 别名]
# 或者: from matplotlib.colors.LinearSegmentedColormap import set_over [as 别名]
def mds(MATRIX_FILE, DIMENSIONS, N_ITERATIONS, IMAGES_EVERY, STATION_BLOCK_SIZE, N_NEARBY_STATIONS, DEBUG_OUTPUT, STATUS_FUNCTION, GRAPH_FUNCTION) :

        print 'Loading matrix...'
        npz = np.load(MATRIX_FILE)
        station_coords = npz['station_coords']
        grid_dim       = npz['grid_dim']
        matrix         = npz['matrix'].astype(np.int32)

        # EVERYTHING SHOULD BE IN FLOAT32 for ease of debugging. even times.
        # Matrix and others should be textures, arrays, or in constant memory, to do cacheing.
        # As it is, I'm doing explicit cacheing.

        # force OD matrix symmetry for test
        # THIS was responsible for the coordinate drift!!!
        # need to symmetrize it before copy to device
        matrix = (matrix + matrix.T) / 2

        station_coords_int = station_coords.round().astype(np.int32)

        # to be removed when textures are working
        station_coords_gpu = gpuarray.to_gpu(station_coords_int)
        matrix_gpu = gpuarray.to_gpu(matrix)

        max_x, max_y = grid_dim
        n_gridpoints = int(max_x * max_y)
        n_stations   = len(station_coords)

        cuda_grid_shape = ( int( math.ceil( float(max_x)/CUDA_BLOCK_SHAPE[0] ) ), int( math.ceil( float(max_y)/CUDA_BLOCK_SHAPE[1] ) ) )

        print "\n----PARAMETERS----"
        print "Input file:            ", MATRIX_FILE
        print "Number of stations:    ", n_stations
        print "OD matrix shape:       ", matrix.shape    
        print "Station coords shape:  ", station_coords_int.shape 
        print "Station cache size:    ", N_NEARBY_STATIONS
        print "Map dimensions:        ", grid_dim
        print "Number of map points:  ", n_gridpoints
        print "Target space dimensionality: ", DIMENSIONS
        print "CUDA block dimensions: ", CUDA_BLOCK_SHAPE 
        print "CUDA grid dimensions:  ", cuda_grid_shape

        assert station_coords.shape == (n_stations, 2)
        assert N_NEARBY_STATIONS <= n_stations
        
        #sys.exit()

        # Make and register custom color map for pylab graphs

        cdict = {'red':   ((0.0,  0.0, 0.0),
                           (0.2,  0.0, 0.0),
                           (0.4,  0.9, 0.9),
                           (1.0,  0.0, 0.0)),

                 'green': ((0.0,  0.0, 0.1),
                           (0.05, 0.9, 0.9),
                           (0.1,  0.0, 0.0),
                           (0.4,  0.9, 0.9),
                           (0.6,  0.0, 0.0),
                           (1.0,  0.0, 0.0)),

                 'blue':  ((0.0,  0.0, 0.0),
                           (0.05, 0.0, 0.0),
                           (0.2,  0.9, 0.9),
                           (0.3,  0.0, 0.0),
                           (1.0,  0.0, 0.0))}

        mymap = LinearSegmentedColormap('mymap', cdict)
        mymap.set_over( (1.0, 0.0, 1.0) )
        mymap.set_bad ( (0.0, 0.0, 0.0) )
        pl.plt.register_cmap(cmap=mymap)

        # set up arrays for calculations

        coords_gpu = gpuarray.to_gpu(np.random.random( (max_x, max_y, DIMENSIONS) ).astype(np.float32))   # initialize coordinates to random values in range 0...1
        forces_gpu = gpuarray.zeros( (int(max_x), int(max_y), DIMENSIONS), dtype=np.float32 )             # 3D float32 accumulate forces over one timestep
        weights_gpu = gpuarray.zeros( (int(max_x), int(max_y)),             dtype=np.float32 )             # 2D float32 cell error accumulation
        errors_gpu = gpuarray.zeros( (int(max_x), int(max_y)),             dtype=np.float32 )             # 2D float32 cell error accumulation
        near_stations_gpu = gpuarray.zeros( (cuda_grid_shape[0], cuda_grid_shape[1], N_NEARBY_STATIONS), dtype=np.int32)

        debug_gpu     = gpuarray.zeros( n_gridpoints, dtype = np.int32 )
        debug_img_gpu = gpuarray.zeros_like( errors_gpu )

        print "\n----COMPILATION----"
        # times could be merged into forces kernel, if done by pixel not station.
        # integrate kernel could be GPUArray operation; also helps clean up code by using GPUArrays.
        # DIM should be replaced by python script, so as not to define twice. 
        src = open("unified_mds.cu").read()
        src = src.replace( 'N_NEARBY_STATIONS_PYTHON', str(N_NEARBY_STATIONS) )
        src = src.replace( 'N_STATIONS_PYTHON', str(n_stations) )
        src = src.replace( 'DIMENSIONS_PYTHON', str(DIMENSIONS) )
        mod = SourceModule(src, options=["--ptxas-options=-v"])
        stations_kernel  = mod.get_function("stations"  )
        forces_kernel    = mod.get_function("forces"  )
        integrate_kernel = mod.get_function("integrate")

        matrix_texref         = mod.get_texref('tex_matrix')
        station_coords_texref = mod.get_texref('tex_station_coords')
        near_stations_texref  = mod.get_texref('tex_near_stations')
        #ts_coords_texref  = mod.get_texref('tex_ts_coords') could be a 4-channel 2 dim texture, or 3 dim texture. or just 1D.

#.........这里部分代码省略.........
开发者ID:abyrd,项目名称:metric-embedding,代码行数:103,代码来源:mds.py

示例8: run

# 需要导入模块: from matplotlib.colors import LinearSegmentedColormap [as 别名]
# 或者: from matplotlib.colors.LinearSegmentedColormap import set_over [as 别名]
    def run (self) :
        cuda.init()
        self.cuda_dev = cuda.Device(0)
        self.cuda_context = self.cuda_dev.make_context()

#        print 'Loading matrix...'
#        npz = np.load(self.MATRIX_FILE)
#        station_coords = npz['station_coords']
#        grid_dim       = npz['grid_dim']
#        matrix         = npz['matrix']
        station_coords  = self.station_coords
        grid_dim        = self.grid_dim
        matrix          = self.matrix
        nearby_stations = self.nearby_stations    

        # EVERYTHING SHOULD BE IN FLOAT32 for ease of debugging. even times.
        # Matrix and others should be textures, arrays, or in constant memory, to do cacheing.
        
        # make matrix symmetric before converting to int32. this avoids halving the pseudo-infinity value.
        matrix = (matrix + matrix.T) / 2
       #print np.where(matrix == np.inf)
        matrix[matrix == np.inf] = 99999999
        # nan == nan is False because any operation involving nan is False !
        # must use specific isnan function. however, inf works like a normal number.
        matrix[np.isnan(matrix)] = 99999999
        #matrix[matrix >= 60 * 60 * 3] = 0
        matrix = matrix.astype(np.int32)
        #matrix += 60 * 5
        #matrix = np.nan_to_num(matrix)
        print matrix
        
        # force OD matrix symmetry for test
        # THIS was responsible for the coordinate drift!!!
        # need to symmetrize it before copy to device
#        matrix = (matrix + matrix.T) / 2
#        print matrix

        #print np.any(matrix == np.nan)
        #print np.any(matrix == np.inf)

        station_coords_int = station_coords.round().astype(np.int32)

        # to be removed when textures are working
        station_coords_gpu = gpuarray.to_gpu(station_coords_int)
        matrix_gpu = gpuarray.to_gpu(matrix)

        max_x, max_y = grid_dim
        n_gridpoints = int(max_x * max_y)
        n_stations   = len(station_coords)

        cuda_grid_shape = ( int( math.ceil( float(max_x)/CUDA_BLOCK_SHAPE[0] ) ), int( math.ceil( float(max_y)/CUDA_BLOCK_SHAPE[1] ) ) )

        print "\n----PARAMETERS----"
        print "Input file:            ", self.MATRIX_FILE
        print "Number of stations:    ", n_stations
        print "OD matrix shape:       ", matrix.shape    
        print "Station coords shape:  ", station_coords_int.shape 
        print "Station cache size:    ", self.N_NEARBY_STATIONS
        print "Map dimensions:        ", grid_dim
        print "Number of map points:  ", n_gridpoints
        print "Target space dimensionality: ", self.DIMENSIONS
        print "CUDA block dimensions: ", CUDA_BLOCK_SHAPE 
        print "CUDA grid dimensions:  ", cuda_grid_shape

        assert station_coords.shape == (n_stations, 2)
        assert self.N_NEARBY_STATIONS <= n_stations
        
        #sys.exit()

        # Make and register custom color map for pylab graphs

        cdict = {'red':   ((0.0,  0.0, 0.0),
                           (0.2,  0.0, 0.0),
                           (0.4,  0.9, 0.9),
                           (1.0,  0.0, 0.0)),

                 'green': ((0.0,  0.0, 0.1),
                           (0.05, 0.9, 0.9),
                           (0.1,  0.0, 0.0),
                           (0.4,  0.9, 0.9),
                           (0.6,  0.0, 0.0),
                           (1.0,  0.0, 0.0)),

                 'blue':  ((0.0,  0.0, 0.0),
                           (0.05, 0.0, 0.0),
                           (0.2,  0.9, 0.9),
                           (0.3,  0.0, 0.0),
                           (1.0,  0.0, 0.0))}

        mymap = LinearSegmentedColormap('mymap', cdict)
        mymap.set_over( (1.0, 0.0, 1.0) )
        mymap.set_bad ( (0.0, 0.0, 0.0) )
        #pl.plt.register_cmap(cmap=mymap)

        # set up arrays for calculations

        coords_gpu        = gpuarray.to_gpu(np.random.random( (max_x, max_y, self.DIMENSIONS) ).astype(np.float32))   # initialize coordinates to random values in range 0...1
        forces_gpu        = gpuarray.zeros( (int(max_x), int(max_y), self.DIMENSIONS), dtype=np.float32 )             # 3D float32 accumulate forces over one timestep
        weights_gpu       = gpuarray.zeros( (int(max_x), int(max_y)),                  dtype=np.float32 )             # 2D float32 cell error accumulation
        errors_gpu        = gpuarray.zeros( (int(max_x), int(max_y)),                  dtype=np.float32 )             # 2D float32 cell error accumulation
#.........这里部分代码省略.........
开发者ID:abyrd,项目名称:metric-embedding,代码行数:103,代码来源:qt_mds.py


注:本文中的matplotlib.colors.LinearSegmentedColormap.set_over方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。