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


Python ScalarMappable.set_array方法代码示例

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


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

示例1: scatter3d

# 需要导入模块: from matplotlib.cm import ScalarMappable [as 别名]
# 或者: from matplotlib.cm.ScalarMappable import set_array [as 别名]
def scatter3d(x,y,z, cs, colorsMap='jet'):
    cm = plt.get_cmap(colorsMap)
    cNorm = Normalize(vmin=min(cs), vmax=max(cs))
    scalarMap = ScalarMappable(norm=cNorm, cmap=cm)
    ax.scatter(x, y, z, c=scalarMap.to_rgba(cs), s=5, linewidth=0)
    scalarMap.set_array(cs)
    plt.show()
开发者ID:hermitdemschoenenleben,项目名称:muenster,代码行数:9,代码来源:caustic_pos.py

示例2: ColorbarWidget

# 需要导入模块: from matplotlib.cm import ScalarMappable [as 别名]
# 或者: from matplotlib.cm.ScalarMappable import set_array [as 别名]
class ColorbarWidget(QWidget):

    def __init__(self, parent=None):
        super(ColorbarWidget, self).__init__(parent)
        fig = Figure()
        rect = 0.25, 0.05, 0.1, 0.90
        self.cb_axes = fig.add_axes(rect)
        self.canvas = FigureCanvas(fig)
        self.setLayout(QVBoxLayout())
        self.layout().addWidget(self.canvas)
        self.button = QPushButton("Update")
        self.layout().addWidget(self.button)
        self.button.pressed.connect(self._update_cb_scale)

        self._create_colorbar(fig)

    def _create_colorbar(self, fig):
        self.mappable = ScalarMappable(norm=SymLogNorm(0.0001, 1,vmin=-10., vmax=10000.),
                                  cmap=DEFAULT_CMAP)
        self.mappable.set_array([])
        fig.colorbar(self.mappable, ax=self.cb_axes, cax=self.cb_axes)

    def _update_cb_scale(self):
        self.mappable.colorbar.remove()
        rect = 0.25, 0.05, 0.1, 0.90
        self.cb_axes = self.canvas.figure.add_axes(rect)
        self.mappable = ScalarMappable(Normalize(30, 4300),
                                   cmap=DEFAULT_CMAP)
        self.mappable.set_array([])
        self.canvas.figure.colorbar(self.mappable, ax=self.cb_axes, cax=self.cb_axes)
        self.canvas.draw()
开发者ID:martyngigg,项目名称:sandbox,代码行数:33,代码来源:cbar.py

示例3: getcolor

# 需要导入模块: from matplotlib.cm import ScalarMappable [as 别名]
# 或者: from matplotlib.cm.ScalarMappable import set_array [as 别名]
 def getcolor(self, V, F):
     dS = numpy.empty(len(F))
     for i, f in enumerate(F):
         v = V[f][0]
         dS[i] = v[0] * v[0] + v[1] * v[1] + v[2] * v[2]
     cmap = ScalarMappable(cmap='jet')
     cmap.set_array(dS)
     return cmap, cmap.to_rgba(dS)
开发者ID:jianmingtang,项目名称:PIC-tools,代码行数:10,代码来源:mplFig.py

示例4: plot_events

# 需要导入模块: from matplotlib.cm import ScalarMappable [as 别名]
# 或者: from matplotlib.cm.ScalarMappable import set_array [as 别名]
def plot_events(mapobj,axisobj,catalog,label= None, color='depth', pretty = False, colormap=None, 
             llat = -90, ulat = 90, llon = -180, ulon = 180, figsize=(16,24), 
             par_range = (-90., 120., 30.), mer_range = (0., 360., 60.),
             showHour = False, M_above = 0.0, location = 'World', min_size=1, max_size=8,**kwargs):

    '''Simplified version of plot_event'''

    import matplotlib.pyplot as plt
    from matplotlib.colors import Normalize
    from matplotlib.cm import ScalarMappable

    lats, lons, mags, times, labels, colors = get_event_info(catalog, M_above, llat, ulat, llon, ulon, color, label)
                    
    min_color = min(colors)
    max_color = max(colors)

    if colormap is None:
        if color == "date":
             colormap = plt.get_cmap()
        else:
            # Choose green->yellow->red for the depth encoding.
             colormap = plt.get_cmap("RdYlGn_r")
                
    scal_map = ScalarMappable(norm=Normalize(min_color, max_color),
                                  cmap=colormap)
    scal_map.set_array(np.linspace(0, 1, 1))

    x, y = mapobj(lons, lats)

    min_mag = 0
    max_mag = 10
    if len(mags) > 1:
        frac = [(_i - min_mag) / (max_mag - min_mag) for _i in mags]
        magnitude_size = [(_i * (max_size - min_size)) ** 2 for _i in frac]
        #magnitude_size = [(_i * min_size) for _i in mags]
        #print magnitude_size
        colors_plot = [scal_map.to_rgba(c) for c in colors]
    else:
        magnitude_size = 15.0 ** 2
        colors_plot = "red"

    quakes = mapobj.scatter(x, y, marker='o', s=magnitude_size, c=colors_plot, zorder=10)
    #mapobj.drawmapboundary(fill_color='aqua')
    #mapobj.drawparallels(np.arange(-90,90,30),labels=[1,0,0,0])
    #mapobj.drawmeridians(np.arange(mapobj.lonmin,mapobj.lonmax+30,60),labels=[0,0,0,1])

    # if len(mags) > 1:
    #     cb = mpl.colorbar.ColorbarBase(ax=axisobj, cmap=colormap, orientation='vertical')
    #     cb.set_ticks([0, 0.25, 0.5, 0.75, 1.0])
    #     color_range = max_color - min_color
    #     cb.set_ticklabels([_i.strftime('%Y-%b-%d') if color == "date" else '%.1fkm' % (_i)
    #             for _i in [min_color, min_color + color_range * 0.25,
    #                    min_color + color_range * 0.50,
    #                    min_color + color_range * 0.75, max_color]])

    return quakes
开发者ID:rmartinshort,项目名称:Interactive_MT,代码行数:58,代码来源:cat_analysis.py

示例5: _create_colorbar

# 需要导入模块: from matplotlib.cm import ScalarMappable [as 别名]
# 或者: from matplotlib.cm.ScalarMappable import set_array [as 别名]
 def _create_colorbar(self, cmap, ncolors, labels, **kwargs):    
     norm = BoundaryNorm(range(0, ncolors), cmap.N)
     mappable = ScalarMappable(cmap=cmap, norm=norm)
     mappable.set_array([])
     mappable.set_clim(-0.5, ncolors+0.5)
     colorbar = plt.colorbar(mappable, **kwargs)
     colorbar.set_ticks(np.linspace(0, ncolors, ncolors+1)+0.5)
     colorbar.set_ticklabels(range(0, ncolors))
     colorbar.set_ticklabels(labels)
     return colorbar
开发者ID:hendrikTpl,项目名称:SEA_traffic_accident_prediction,代码行数:12,代码来源:seattle_choropleth.py

示例6: plot_net_layerwise

# 需要导入模块: from matplotlib.cm import ScalarMappable [as 别名]
# 或者: from matplotlib.cm.ScalarMappable import set_array [as 别名]
def plot_net_layerwise(net, x_spacing=5, y_spacing=10, colors=[], use_labels=True, ax=None, cmap='gist_heat', cbar=False, positions={}):
	if not colors:
		colors = [1] * net.size()
	args = {
		'ax' : ax,
		'node_color' : colors,
		'nodelist' : net.nodes(), # ensure that same order is used throughout for parallel data like colors
		'vmin' : 0,
		'vmax' : 1,
		'cmap' : cmap
	}

	if not positions:
		# compute layer-wise positions of nodes (distance from roots)
		nodes_by_layer = defaultdict(lambda: [])
		def add_to_layer(n,l):
			nodes_by_layer[l].append(n)
		net.bfs_traverse(net.get_roots(), add_to_layer)


		positions = {}
		for l, nodes in nodes_by_layer.iteritems():
			y = -l*y_spacing
			# reorder layer lexicographically
			nodes.sort(key=lambda n: n.get_name())
			width = (len(nodes)-1) * x_spacing
			for i,n in enumerate(nodes):
				x = x_spacing*i - width/2
				positions[n] = (x,y)
	args['pos'] = positions

	if use_labels:
		labels = {n:n.get_name() for n in net.iter_nodes()}
		args['labels'] = labels

	if ax is None:
		ax = plt.figure().add_subplot(1,1,1)
	nxg = net_to_digraph(net)
	nx.draw_networkx(nxg, **args)
	ax.tick_params(axis='x', which='both', bottom='off', top='off', labelbottom='off')
	ax.tick_params(axis='y', which='both', left='off', right='off', labelleft='off')
	
	if cbar:
		color_map = ScalarMappable(cmap=cmap)
		color_map.set_clim(vmin=0, vmax=1)
		color_map.set_array(np.array([0,1]))
		plt.colorbar(color_map, ax=ax)

	ax.set_aspect('equal')
	# zoom out slightly to avoid cropping issues with nodes
	xl = ax.get_xlim()
	yl = ax.get_ylim()
	ax.set_xlim(xl[0]-x_spacing/2, xl[1]+x_spacing/2)
	ax.set_ylim(yl[0]-y_spacing/2, yl[1]+y_spacing/2)
开发者ID:wrongu,项目名称:sampling-dynamics,代码行数:56,代码来源:visualize.py

示例7: densityplot2

# 需要导入模块: from matplotlib.cm import ScalarMappable [as 别名]
# 或者: from matplotlib.cm.ScalarMappable import set_array [as 别名]
    def densityplot2(self,modelname='Model',refname='Ref',units = 'mmol m-3',sub = 'med'):
        '''
        opectool like density plot
        
        Ref is in x axis
        Model  in y axis
        
        Args
         - *modelname* (optional) string , default ='Model'
         - *refname*   (optional) string , default ='Ref'
         - *units*     (optional) string , default ='mmol m-3'
         - *sub*       (optional) string , default ='med'
        
        
        Returns: a matplotlib Figure object and a matplotlib Axes object
        '''
        
        fig, ax = plt.subplots()
        plt.title('%s Density plot of %s and %s\nNumber of considered matchups: %s' % (sub, modelname, refname, self.number()))
        cmap = 'spectral_r'
        axis_min = min(self.Ref.min(),self.Model.min())
        axis_max = max(self.Ref.max(),self.Model.max())
        extent = [axis_min, axis_max, axis_min, axis_max]

        hexbin = ax.hexbin(self.Ref, self.Model, bins=None, extent=extent, cmap=cmap)
        data = hexbin.get_array().astype(np.int32)
        MAX = data.max()

        for nticks in range(10,2,-1):
            float_array=np.linspace(0,MAX,nticks)
            int___array = float_array.astype(np.int32)
            if np.all(float_array == int___array ):
                break

        mappable = ScalarMappable(cmap=cmap)
        mappable.set_array(data)
        #fig.colorbar(mappable, ticks = int___array, ax=ax)
        cbar = fig.colorbar(mappable, ax=ax)
        labels = cbar.ax.get_yticklabels()
        FloatNumberFlag = False
        for label in labels:
            numstr = str(label.get_text())
            if numstr.find(".") > -1:
                FloatNumberFlag = True

        if FloatNumberFlag:
            cbar.remove()
            cbar = fig.colorbar(mappable, ticks = int___array, ax=ax)

        ax.set_xlabel('%s %s' % (refname,  units))
        ax.set_ylabel('%s %s' % (modelname,units))
        ax.grid()
        return fig,ax
开发者ID:inogs,项目名称:bit.sea,代码行数:55,代码来源:statistics.py

示例8: custom_colorbar

# 需要导入模块: from matplotlib.cm import ScalarMappable [as 别名]
# 或者: from matplotlib.cm.ScalarMappable import set_array [as 别名]
def custom_colorbar(cmap, ncolors, breaks, **kwargs):
    from matplotlib.colors import BoundaryNorm
    from matplotlib.cm import ScalarMappable
    import matplotlib.colors as mplc

    breaklabels = ['No Counts']+["> %d counts"%(perc) for perc in breaks[:-1]]

    norm = BoundaryNorm(range(0, ncolors), cmap.N)
    mappable = ScalarMappable(cmap=cmap, norm=norm)
    mappable.set_array([])
    mappable.set_clim(-0.5, ncolors+0.5)
    colorbar = plt.colorbar(mappable, **kwargs)
    colorbar.set_ticks(np.linspace(0, ncolors, ncolors+1)+0.5)
    colorbar.set_ticklabels(range(0, ncolors))
    colorbar.set_ticklabels(breaklabels)
    return colorbar
开发者ID:RaySSharma,项目名称:crime-activity-seattle,代码行数:18,代码来源:choropleth.py

示例9: set_data

# 需要导入模块: from matplotlib.cm import ScalarMappable [as 别名]
# 或者: from matplotlib.cm.ScalarMappable import set_array [as 别名]
    def set_data(self, x_data, y_data, axis_min, axis_max, matchup_count, log):
        logging.debug('Creating density plot...')

        cmap = 'spectral_r'
        extent = [axis_min, axis_max, axis_min, axis_max]
        if log:
            bin_spec = 'log'
        else:
            bin_spec = None
        hexbin = self.ax.hexbin(x_data, y_data, bins=bin_spec, extent=extent, cmap=cmap)
        data = hexbin.get_array()

        mappable = ScalarMappable(cmap=cmap)
        mappable.set_array(data)
        self.fig.colorbar(mappable, ax=self.ax)

        logging.debug('...success!')
        self.update_title(matchup_count)
开发者ID:bcdev,项目名称:opec-tools,代码行数:20,代码来源:plotter.py

示例10: custom_colorbar

# 需要导入模块: from matplotlib.cm import ScalarMappable [as 别名]
# 或者: from matplotlib.cm.ScalarMappable import set_array [as 别名]
def custom_colorbar(cmap, ncolors, labels, **kwargs):    
    """Create a custom, discretized colorbar with correctly formatted/aligned labels.
    
    cmap: the matplotlib colormap object you plan on using for your graph
    ncolors: (int) the number of discrete colors available
    labels: the list of labels for the colorbar. Should be the same length as ncolors.
    """
    from matplotlib.colors import BoundaryNorm
    from matplotlib.cm import ScalarMappable
        
    norm = BoundaryNorm(range(0, ncolors), cmap.N)
    mappable = ScalarMappable(cmap=cmap, norm=norm)
    mappable.set_array([])
    mappable.set_clim(-0.5, ncolors+0.5)
    colorbar = plt.colorbar(mappable, **kwargs)
    colorbar.set_ticks(np.linspace(0, ncolors, ncolors+1)+0.5)
    colorbar.set_ticklabels(range(0, ncolors))
    colorbar.set_ticklabels(labels)
    return colorbar
开发者ID:tylerhartley,项目名称:personal,代码行数:21,代码来源:latitude-blogcopy.py

示例11: make_plot

# 需要导入模块: from matplotlib.cm import ScalarMappable [as 别名]
# 或者: from matplotlib.cm.ScalarMappable import set_array [as 别名]
  def make_plot(self, val, cct, clm,
                cmap = 'jet', cmap_norm = None,
                cmap_vmin = None, cmap_vmax = None):

    # make color mapping
    smap = ScalarMappable(cmap_norm, cmap)
    smap.set_clim(cmap_vmin, cmap_vmax)
    smap.set_array(val)
    bin_colors = smap.to_rgba(val)

    # make patches
    patches = []
    for i_c, i_clm in enumerate(clm):
      patches.append(Rectangle((i_clm[0],  i_clm[2]),
                                i_clm[1] - i_clm[0],
                                i_clm[3] - i_clm[2]))
    patches_colle = PatchCollection(patches)
    patches_colle.set_edgecolor('face')
    patches_colle.set_facecolor(bin_colors)

    return patches_colle, smap
开发者ID:shiaki,项目名称:astro-viskit,代码行数:23,代码来源:adapt_hist.py

示例12: _custom_colorbar

# 需要导入模块: from matplotlib.cm import ScalarMappable [as 别名]
# 或者: from matplotlib.cm.ScalarMappable import set_array [as 别名]
def _custom_colorbar(cmap, ncolors, labels, **kwargs):
        """Create a custom, discretized colorbar with correctly formatted/aligned labels.
        It was inspired mostly by the example provided in http://beneathdata.com/how-to/visualizing-my-location-history/

        :param cmap: the matplotlib colormap object you plan on using for your graph
        :param ncolors: (int) the number of discrete colors available
        :param labels: the list of labels for the colorbar. Should be the same length as ncolors.

        :return: custom colorbar
        """

        if ncolors <> len(labels):
            raise MapperError("Number of colors is not compatible with the number of labels")
        else:
            norm = BoundaryNorm(range(0, ncolors), cmap.N)
            mappable = ScalarMappable(cmap=cmap)
            mappable.set_array([])
            mappable.set_clim(-0.5, ncolors+0.5)
            colorbar = plt.colorbar(mappable, **kwargs)
            colorbar.set_ticks(np.linspace(0, ncolors, ncolors+1)+0.5)
            colorbar.set_ticklabels(range(0, ncolors))
            colorbar.set_ticklabels(labels)
            return colorbar
开发者ID:ds-ga-1007,项目名称:final_project,代码行数:25,代码来源:Mapper_utils.py

示例13: make_cmap_sm_norm

# 需要导入模块: from matplotlib.cm import ScalarMappable [as 别名]
# 或者: from matplotlib.cm.ScalarMappable import set_array [as 别名]
def make_cmap_sm_norm(d=None,clim=None,cmap=None):
	if cmap == 'red_blue':
		cmap = red_blue_cm()
	if cmap == 'banas_cm':
		if clim==None:
			cmap = banas_cm(np.min(d[:]),np.min(d[:]),np.max(d[:]),np.max(d[:]))
		elif len(clim) == 2:
			cmap = banas_cm(clim[0],clim[0],clim[1],clim[1])
		elif len(clim) == 4:
			cmap = banas_cm(clim[0],clim[1],clim[2],clim[3])
	elif cmap == 'banas_hsv_cm':
		if clim==None:
			cmap = banas_hsv_cm(np.min(d[:]),np.min(d[:]),np.max(d[:]),np.max(d[:]))
		elif len(clim) == 2:
			cmap = banas_hsv_cm(clim[0],clim[0],clim[1],clim[1])
		elif len(clim) == 4:
			cmap = banas_hsv_cm(clim[0],clim[1],clim[2],clim[3])
	
	norm = Normalize(vmin=clim[0],vmax=clim[-1],clip=False)
	sm = ScalarMappable(norm=norm,cmap=cmap)
	sm.set_clim(vmin=clim[0],vmax=clim[-1])
	sm.set_array(np.array([0]))

	return cmap,sm,norm
开发者ID:HyeonJeongKim,项目名称:tools,代码行数:26,代码来源:plot_utils.py

示例14: plot_whole_genome_heatmap

# 需要导入模块: from matplotlib.cm import ScalarMappable [as 别名]
# 或者: from matplotlib.cm.ScalarMappable import set_array [as 别名]
    def plot_whole_genome_heatmap(self, data=None, data2=None, triangle=False,
                                  log=True, diagonal_markers=False,
                                  compare=False, chrlabels=True, title=True,
                                  normalize=False, savepath=False, format='svg',
                                  colormap=False, colorbar=True, cblocation='vertical',
                                  figsize=False, vmin=0,
                                  vmax=None, *args, **kwargs):
        if data is None:
            data = np.log2(self.data+1)
        else:
            if log:
                data = np.log2(data+1)
        if data2 is None:
            try:
                data2 = np.log2(self.data2+1)
            except AttributeError:
                pass
        if not colormap:
            colormap = self.cmap
        else:
            colormap = cmap.get_cmap(colormap)
        if not figsize:
            figsize = (15, 10)
        if savepath:
            plt.ioff()
        length, height = data.shape
        if triangle:
            data = self.make_triangle(data)
            try:
                data2 = self.make_triangle(data2)
            except:
                pass
        if normalize:
            data = self._normalize_array(data)
            if data2 is not None:
                data2 = self._normalize_array(data2)

        def determine_aspect(shape, extent):
            dx = (extent[1] - extent[0]) / float(shape[1])
            dy = (extent[3] - extent[2]) / float(shape[0])
            return dx / dy
        extent = [0, length*self.resolution,
                  0, length*self.resolution]
        aspect = determine_aspect(data.shape, extent)
        fig = plt.figure(figsize=figsize)
        fig.set_dpi(72)
        self.ax = host_subplot(111)
        self.ax.xaxis.set_tick_params(length=5, direction='out')
        self.ax.yaxis.set_tick_params(length=5, direction='out')

        self.ax.xaxis.set_major_formatter(mticker.FuncFormatter(
                                          self._nice_ticks))
        self.ax.yaxis.set_major_formatter(mticker.FuncFormatter(
                                          self._nice_ticks))
#        self.ax.minorticks_on()
#        self.ax.xaxis.set_minor_locator(MultipleLocator(200000))
#        self.ax.tick_params(axis='x', which='minor', bottom='on', top='off',
#                            direction='out', length=2, width=0.01)
#        self.ax.tick_params(axis='y', which='minor', left='on', right='off',
#                            direction='out', length=2, width=0.01)
        self.ax.tick_params(axis='x', which='major', bottom='on', top='on',
                            labelbottom='on', labelsize=12)
        self.ax.tick_params(axis='y', which='major', left='on', right='on',
                            labelleft='on', labelsize=12)
        self.ax.set(adjustable='box-forced')
        if chrlabels:
            self.axChrLabels = self.ax.twin()
            self.locations = [sum(i)/2*self.resolution for i in self.boundaries]
            self.axChrLabels.set_xticks(self.locations)
            if triangle:
                self.axChrLabels.yaxis.set_visible(False)
                self.ax.yaxis.set_visible(True)
                self.axChrLabels.xaxis.tick_bottom()
            else:
                self.axChrLabels.yaxis.tick_right()
                self.axChrLabels.xaxis.tick_top()
            self.axChrLabels.set_xticklabels(self.chromosomes, fontsize=15)
            self.axChrLabels.set_yticks(self.locations)
            self.axChrLabels.set_yticklabels(self.chromosomes, fontsize=15)
            self.axChrLabels.xaxis.set_tick_params(length=0)
            self.axChrLabels.yaxis.set_tick_params(length=0)
#        if colorbar:
#            self.divider = make_axes_locatable(self.ax)
#            self.ax_cb = self.divider.append_axes('right', size=0.1, pad=0.01)
        if diagonal_markers:
            if vmax is False:
                vmax = np.nanmax(data)
            norm = plt.Normalize(vmin, vmax)
            data = colormap(norm(data))
            for multiple in diagonal_markers.keys():
                for start, end in self.boundaries:
                    for i in range(start, end, multiple//self.resolution):
                        data[i, i] = mcolors.ColorConverter().to_rgba(
                                                    diagonal_markers[multiple])
            im = ScalarMappable(norm, colormap)
            im.set_array(data)
            if colorbar:
                self.colorbar = plt.colorbar(im)
        if title:
            plt.suptitle(self._make_title(), fontsize=15)
#.........这里部分代码省略.........
开发者ID:Phlya,项目名称:hicplotlib,代码行数:103,代码来源:HiCPlot.py

示例15: plot_basemap

# 需要导入模块: from matplotlib.cm import ScalarMappable [as 别名]
# 或者: from matplotlib.cm.ScalarMappable import set_array [as 别名]
def plot_basemap(lons, lats, size, color, labels=None, projection='global',
                 resolution='l', continent_fill_color='0.8',
                 water_fill_color='1.0', colormap=None, colorbar=None,
                 marker="o", title=None, colorbar_ticklabel_format=None,
                 show=True, fig=None, **kwargs):  # @UnusedVariable
    """
    Creates a basemap plot with a data point scatter plot.

    :type lons: list/tuple of floats
    :param lons: Longitudes of the data points.
    :type lats: list/tuple of floats
    :param lats: Latitudes of the data points.
    :type size: float or list/tuple of floats
    :param size: Size of the individual points in the scatter plot.
    :type color: list/tuple of floats (or objects that can be
        converted to floats, like e.g.
        :class:`~obspy.core.utcdatetime.UTCDateTime`)
    :param color: Color information of the individual data points to be
        used in the specified color map (e.g. origin depths,
        origin times).
    :type labels: list/tuple of str
    :param labels: Annotations for the individual data points.
    :type projection: str, optional
    :param projection: The map projection.
        Currently supported are:

            * ``"global"`` (Will plot the whole world.)
            * ``"ortho"`` (Will center around the mean lat/long.)
            * ``"local"`` (Will plot around local events)

        Defaults to "global".
    :type resolution: str, optional
    :param resolution: Resolution of the boundary database to use. Will be
        based directly to the basemap module. Possible values are:

            * ``"c"`` (crude)
            * ``"l"`` (low)
            * ``"i"`` (intermediate)
            * ``"h"`` (high)
            * ``"f"`` (full)

        Defaults to ``"l"``. For compatibility, you may also specify any of the
        Cartopy resolutions defined in :func:`plot_cartopy`.
    :type continent_fill_color: Valid matplotlib color, optional
    :param continent_fill_color:  Color of the continents. Defaults to
        ``"0.9"`` which is a light gray.
    :type water_fill_color: Valid matplotlib color, optional
    :param water_fill_color: Color of all water bodies.
        Defaults to ``"white"``.
    :type colormap: str, any matplotlib colormap, optional
    :param colormap: The colormap for color-coding the events as provided
        in `color` kwarg.
        The event with the smallest `color` property will have the
        color of one end of the colormap and the event with the highest
        `color` property the color of the other end with all other events
        in between.
        Defaults to None which will use the default matplotlib colormap.
    :type colorbar: bool, optional
    :param colorbar: When left `None`, a colorbar is plotted if more than one
        object is plotted. Using `True`/`False` the colorbar can be forced
        on/off.
    :type title: str
    :param title: Title above plot.
    :type colorbar_ticklabel_format: str or function or
        subclass of :class:`matplotlib.ticker.Formatter`
    :param colorbar_ticklabel_format: Format string or Formatter used to format
        colorbar tick labels.
    :type show: bool
    :param show: Whether to show the figure after plotting or not. Can be used
        to do further customization of the plot before showing it.
    :type fig: :class:`matplotlib.figure.Figure`
    :param fig: Figure instance to reuse, returned from a previous
        :func:`plot_basemap` call. If a previous basemap plot is reused, any
        kwargs regarding the basemap plot setup will be ignored (i.e.
        `projection`, `resolution`, `continent_fill_color`,
        `water_fill_color`). Note that multiple plots using colorbars likely
        are problematic, but e.g. one station plot (without colorbar) and one
        event plot (with colorbar) together should work well.
    """
    import matplotlib.pyplot as plt
    min_color = min(color)
    max_color = max(color)

    if any([isinstance(c, (datetime.datetime, UTCDateTime)) for c in color]):
        datetimeplot = True
        color = [
            (np.isfinite(float(t)) and
             date2num(getattr(t, 'datetime', t)) or
             np.nan)
            for t in color]
    else:
        datetimeplot = False

    scal_map = ScalarMappable(norm=Normalize(min_color, max_color),
                              cmap=colormap)
    scal_map.set_array(np.linspace(0, 1, 1))

    # The colorbar should only be plotted if more then one event is
    # present.
    if colorbar is None:
#.........这里部分代码省略.........
开发者ID:FMassin,项目名称:obspy,代码行数:103,代码来源:maps.py


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