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


Python NonUniformImage.set_data方法代码示例

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


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

示例1: plot_spectrogram

# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_data [as 别名]
def plot_spectrogram(spec, Xd=(0,1), Yd=(0,1), norm=colo.LogNorm(vmin=0.000001), figname=None):
    #
    x_min, x_max = Xd
    y_min, y_max = Yd
    #
    fig = plt.figure(num=figname)
    nf = len(spec)
    for ch, data in enumerate(spec):
        #print ch, data.shape
        x = np.linspace(x_min, x_max, data.shape[0])
        y = np.linspace(y_min, y_max, data.shape[1])
        #print x[0],x[-1],y[0],y[-1]
        ax = fig.add_subplot(nf*100+11+ch)
        im = NonUniformImage(ax, interpolation='bilinear', cmap=cm.gray_r,
                norm=norm)
        im.set_data(x, y, data.T)
        ax.images.append(im)
        ax.set_xlim(x_min, x_max)
        ax.set_ylim(y_min, y_max)
        ax.set_title('Channel %d' % ch)
        #ax.set_xlabel('timeline')
        ax.set_ylabel('frequency')
        print 'Statistics: max<%.3f> min<%.3f> mean<%.3f> median<%.3f>' % (data.max(), data.min(), data.mean(), np.median(data))
    #
    plt.show()
开发者ID:dongying,项目名称:dear,代码行数:27,代码来源:spectrogram.py

示例2: plot_spectrogram

# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_data [as 别名]
def plot_spectrogram(spec, Xd=(0,1), Yd=(0,1)):
	import matplotlib
	#matplotlib.use('GTKAgg')
	import matplotlib.pyplot as plt
	import matplotlib.cm as cm
	from matplotlib.image import NonUniformImage
	import matplotlib.colors as colo
	#
	x_min, x_max = Xd
	y_min, y_max = Yd
	#
	fig = plt.figure()
	nf = len(spec)
	for ch, data in enumerate(spec):
		#print ch, data.shape
		x = numpy.linspace(x_min, x_max, data.shape[0])
		y = numpy.linspace(y_min, y_max, data.shape[1])
		#print x[0],x[-1],y[0],y[-1]
		ax = fig.add_subplot(nf*100+11+ch)
		im = NonUniformImage(ax, interpolation='bilinear', cmap=cm.gray_r,
				norm=colo.LogNorm(vmin=.00001))
		im.set_data(x, y, data.T)
		ax.images.append(im)
		ax.set_xlim(x_min, x_max)
		ax.set_ylim(y_min, y_max)
		ax.set_title('Channel %d' % ch)
		#ax.set_xlabel('timeline')
		ax.set_ylabel('frequency')
		print 'Statistics: max<%.3f> min<%.3f> mean<%.3f> median<%.3f>' % (data.max(), data.min(), data.mean(), numpy.median(data))
	#
	plt.show()
开发者ID:creasyw,项目名称:humming,代码行数:33,代码来源:spectrum.py

示例3: _update3

# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_data [as 别名]
def _update3(itr,D,x,soln,t,ax,time):
  N = 100
  #ax.clear()
  buff = 200.0
  minx = np.min(x[:,0])
  maxx = np.max(x[:,0])
  miny = np.min(x[:,1])
  maxy = np.max(x[:,1])
  ax.set_xlim((minx-buff/2,maxx+buff/2))
  ax.set_ylim((miny-buff/2,maxy+buff/2))
  square = Polygon([(minx-buff,miny-buff),
                    (minx-buff,maxy+buff),
                    (maxx+buff,maxy+buff),
                    (maxx+buff,miny-buff),
                    (minx-buff,miny-buff)])
  ax.add_artist(PolygonPatch(square.difference(D),alpha=1.0,color='k',zorder=1))
  xitp = np.linspace(minx,maxx,N)
  yitp = np.linspace(miny,maxy,N)
  xgrid,ygrid = np.meshgrid(xitp,yitp)
  xflat = xgrid.flatten()
  yflat = ygrid.flatten()
  ax.images = []
  im =NonUniformImage(ax,interpolation='bilinear',
                         cmap='cubehelix',
                         extent=(minx,maxx,miny,maxy))
  val = soln[itr](zip(xflat,yflat))
  val = np.sqrt(np.sum(val**2,1))
  im.set_data(xitp,yitp,np.reshape(val,(N,N)))  
  ax.images.append(im)
  t.set_text('t: %s s' % time[itr])
  return ax,t
开发者ID:treverhines,项目名称:SeisRBF,代码行数:33,代码来源:plot.py

示例4: plotDensity

# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_data [as 别名]
def plotDensity(ax, x, result):
    N = len(result["moments"][0])
    y = np.linspace(0, 1, len(result["density"][0]))
    z = np.log(1 + np.array(zip(*result["density"])))
    im = NonUniformImage(ax, norm=Normalize(0, 5, clip=True), interpolation="nearest", cmap=cm.Greys)
    im.set_data(x, y, z)
    ax.images.append(im)
开发者ID:pbenner,项目名称:adaptive-sampling,代码行数:9,代码来源:visualization.py

示例5: _do_plot2

# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_data [as 别名]
def _do_plot2(x, y, z, fname, min_pitch):    
    fig = figure(figsize=(15,7.5+7.5/2))

    #fig.suptitle('Narmour')
    ax = fig.add_subplot(111)

    im = NonUniformImage(ax, interpolation=None, extent=(min(x)-1, max(x)+1, min(y)-1, max(y)+1))
    im.set_data(x, y, z)
    ax.images.append(im)
    ax.set_xlim(min(x)-1, max(x)+1)
    ax.set_ylim(min(y)-1, max(y)+1)

    def format_pitch(i, pos=None):
        if int(i) != i: import ipdb;ipdb.set_trace()
        return Note(int(i + min_pitch)%12).get_pitch_name()[:-1]


    ax.set_xlabel('Segunda nota')
    ax.axes.xaxis.set_major_formatter(ticker.FuncFormatter(format_pitch))
    ax.axes.xaxis.set_major_locator(ticker.MultipleLocator(base=1.0))

    ax.set_ylabel('Primer nota')
    ax.axes.yaxis.set_major_formatter(ticker.FuncFormatter(format_pitch))
    ax.axes.yaxis.set_major_locator(ticker.MultipleLocator())

    cb = plt.colorbar(im)
    pylab.grid(True)
    pylab.savefig(fname)
    pylab.close()
开发者ID:johndpope,项目名称:automusica,代码行数:31,代码来源:plot.py

示例6: test_nonuniformimage_setdata

# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_data [as 别名]
def test_nonuniformimage_setdata():
    ax = plt.gca()
    im = NonUniformImage(ax)
    x = np.arange(3, dtype=np.float64)
    y = np.arange(4, dtype=np.float64)
    z = np.arange(12, dtype=np.float64).reshape((4, 3))
    im.set_data(x, y, z)
    x[0] = y[0] = z[0, 0] = 9.9
    assert im._A[0, 0] == im._Ax[0] == im._Ay[0] == 0, 'value changed'
开发者ID:4over7,项目名称:matplotlib,代码行数:11,代码来源:test_image.py

示例7: plot_interpolant

# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_data [as 别名]
def plot_interpolant(D,interp,x,title='',dim=1,ax=None,scatter=False):
  if ax is None:  
    fig,ax = plt.subplots()
    plt.gca().set_aspect('equal', adjustable='box')
    ax.set_title(title)

  
  buff = 400.0
  N = 150
  minx = np.min(x[:,0])
  maxx = np.max(x[:,0])
  miny = np.min(x[:,1])
  maxy = np.max(x[:,1])
  square = Polygon([(minx-buff,miny-buff),
                    (minx-buff,maxy+buff),
                    (maxx+buff,maxy+buff),
                    (maxx+buff,miny-buff),
                    (minx-buff,miny-buff)])
  ax.add_artist(PolygonPatch(square.difference(D),alpha=1.0,color='k',zorder=1))
  ax.set_xlim((minx-buff,maxx+buff))
  ax.set_ylim((miny-buff,maxy+buff))

  if dim == 1:
    xitp = np.linspace(minx,maxx,N)
    yitp = np.linspace(miny,maxy,N)
    xgrid,ygrid = np.meshgrid(xitp,yitp)
    xflat = xgrid.flatten()
    yflat = ygrid.flatten()
    points = np.zeros((len(xflat),2))
    points[:,0] = xflat
    points[:,1] = yflat
    val = interp(points)
    #val[(np.sqrt(xflat**2+yflat**2) > 6371),:] = 0.0

    im =NonUniformImage(ax,interpolation='bilinear',cmap='cubehelix_r',extent=(minx,maxx,miny,maxy))
    im.set_data(xitp,yitp,np.reshape(val,(N,N)))

    ax.images.append(im)
    if scatter == True:
      p = ax.scatter(x[:,0],
                     x[:,1],
                     c='gray',edgecolor='none',zorder=2,s=10)
    cbar = plt.colorbar(im)

  if dim == 2:
    ax.quiver(x[::3,0],x[::3,1],interp(x)[::3,0],interp(x)[::3,1],color='gray',scale=4000.0,zorder=20)

  return ax
开发者ID:treverhines,项目名称:SeisRBF,代码行数:50,代码来源:PlotSeisRBF.py

示例8: execute

# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_data [as 别名]
 def execute(self):
     pylab.ioff()
     self.figure = pylab.figure()
     self.figure.canvas.mpl_connect('motion_notify_event', self.dataPrinter)
     x = self.fieldContainer.dimensions[-1].data
     y = self.fieldContainer.dimensions[-2].data
     xmin=scipy.amin(x)
     xmax=scipy.amax(x)
     ymin=scipy.amin(y)
     ymax=scipy.amax(y)
     #Support for images with non uniform axes adapted
     #from python-matplotlib-doc/examples/pcolor_nonuniform.py
     ax = self.figure.add_subplot(111)
     vmin = self.fieldContainer.attributes.get('vmin', None)
     vmax = self.fieldContainer.attributes.get('vmax', None)
     if vmin is not None:
         vmin /= self.fieldContainer.unit
     if vmax is not None:
         vmax /= self.fieldContainer.unit
     if MPL_LT_0_98_1 or self.fieldContainer.isLinearlyDiscretised():
         pylab.imshow(self.fieldContainer.maskedData,
                      aspect='auto',
                      interpolation='nearest',
                      vmin=vmin,
                      vmax=vmax,
                      origin='lower',
                      extent=(xmin, xmax, ymin, ymax))
         pylab.colorbar(format=F(self.fieldContainer), ax=ax)
     else:
         im = NonUniformImage(ax, extent=(xmin,xmax,ymin,ymax))
         if vmin is not None or vmax is not None:
             im.set_clim(vmin, vmax)
             im.set_data(x, y, self.fieldContainer.maskedData)
         else:
             im.set_data(x, y, self.fieldContainer.maskedData)
             im.autoscale_None()
         ax.images.append(im)
         ax.set_xlim(xmin,xmax)
         ax.set_ylim(ymin,ymax)
         pylab.colorbar(im,format=F(self.fieldContainer), ax=ax)
     pylab.xlabel(self.fieldContainer.dimensions[-1].shortlabel)
     pylab.ylabel(self.fieldContainer.dimensions[-2].shortlabel)
     pylab.title(self.fieldContainer.label)
     #ax=pylab.gca()
     if self.show:
         pylab.ion()
         pylab.show()
开发者ID:gclos,项目名称:pyphant1,代码行数:49,代码来源:ImageVisualizer.py

示例9: plot_interpolant

# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_data [as 别名]
def plot_interpolant(D,interp,x,title='figure'):
  buff = 100.0
  fig,ax = plt.subplots()
  plt.gca().set_aspect('equal', adjustable='box')

  plt.title(title,fontsize=16)

  N = 200
  minx = np.min(x[:,0])
  maxx = np.max(x[:,0])
  miny = np.min(x[:,1])
  maxy = np.max(x[:,1])
  xitp = np.linspace(minx,maxx,N)
  yitp = np.linspace(miny,maxy,N)
  xgrid,ygrid = np.meshgrid(xitp,yitp)
  xflat = xgrid.flatten()
  yflat = ygrid.flatten()
  points = np.zeros((len(xflat),2))
  points[:,0] = xflat
  points[:,1] = yflat
  val = interp(points)
  val[(np.sqrt(xflat**2+yflat**2) > 6371),:] = 0.0

  square = Polygon([(minx-buff,miny-buff),
                    (minx-buff,maxy+buff),
                    (maxx+buff,maxy+buff),
                    (maxx+buff,miny-buff),
                    (minx-buff,miny-buff)])

  #help(D)
  im =NonUniformImage(ax,interpolation='bilinear',cmap='cubehelix',extent=(minx,maxx,miny,maxy))
  im.set_data(xitp,yitp,np.reshape(val,(N,N)))
  
  ax.images.append(im)
  ax.add_artist(PolygonPatch(square.difference(D),alpha=1.0,color='k',zorder=1))
  p = ax.scatter(x[:,0],
                 x[:,1],
                 c='gray',edgecolor='none',zorder=2,s=10)
  cbar = plt.colorbar(im)
  cbar.ax.set_ylabel(title)
  ax.set_xlim((minx-buff,maxx+buff))
  ax.set_ylim((miny-buff,maxy+buff))
  #fig.colorbar(p)
  return fig
开发者ID:treverhines,项目名称:SeisRBF,代码行数:46,代码来源:plot.py

示例10: _do_plot

# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_data [as 别名]
def _do_plot(x, y, z, fname, max_interval, reference_note=None):    
    fig = figure(figsize=(15,7.5+7.5/2))

    #fig.suptitle('Narmour')
    ax = fig.add_subplot(111)

    im = NonUniformImage(ax, interpolation=None, extent=(min(x), max(x), min(y), max(y)))
    im.set_data(x, y, z)
    ax.images.append(im)
    ax.set_xlim(min(x), max(x))
    ax.set_ylim(min(y), max(y))


    def format_interval_w_ref_note(reference_note):
        def format_interval(i, pos=None):
            if int(i) != i: import ipdb;ipdb.set_trace()
            return Note(int(reference_note.pitch + i - max_interval-1)%12).get_pitch_name()[:-1]
        return format_interval            

    def format_interval_wo_ref_note(x, pos=None):
        if int(x) != x: import ipdb;ipdb.set_trace()
        return int(x-max_interval-1) 
    
    if reference_note is not None:
        format_interval= format_interval_w_ref_note(reference_note)
    else:
        format_interval= format_interval_wo_ref_note
    
    ax.set_xlabel('Intervalo realizado')
    ax.axes.xaxis.set_major_formatter(ticker.FuncFormatter(format_interval_wo_ref_note))
    ax.axes.xaxis.set_major_locator(ticker.MultipleLocator(base=1.0))

    if reference_note is not None:
        ax.set_ylabel('Segunda nota')
    else:
        ax.set_ylabel('Intervalo implicativo')
    ax.axes.yaxis.set_major_formatter(ticker.FuncFormatter(format_interval))
    ax.axes.yaxis.set_major_locator(ticker.MultipleLocator())

    cb = plt.colorbar(im)
    pylab.grid(True)
    pylab.savefig(fname)
    pylab.close()
开发者ID:johndpope,项目名称:automusica,代码行数:45,代码来源:plot.py

示例11: plot_time_frequency

# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_data [as 别名]
def plot_time_frequency(spectrum, interpolation='bilinear', 
    background_color=None, clim=None, dbscale=True, **kwargs):
    """
    Time-frequency plot. Modeled after image_nonuniform.py example 
    spectrum is a dataframe with frequencies in columns and time in rows
    """
    if spectrum is None:
        return None
    
    times = spectrum.index
    freqs = spectrum.columns
    if dbscale:
        z = 10 * np.log10(spectrum.T)
    else:
        z = spectrum.T
    ax = plt.figure().add_subplot(111)
    extent = (times[0], times[-1], freqs[0], freqs[-1])
    
    im = NonUniformImage(ax, interpolation=interpolation, extent=extent)

    if background_color:
        im.get_cmap().set_bad(kwargs['background_color'])
    else:
        z[np.isnan(z)] = 0.0  # replace missing values with 0 color

    if clim:
        im.set_clim(clim)

    if 'cmap' in kwargs:
        im.set_cmap(kwargs['cmap'])

    im.set_data(times, freqs, z)
    ax.set_xlim(extent[0], extent[1])
    ax.set_ylim(extent[2], extent[3])
    ax.images.append(im)
    if 'colorbar_label' in kwargs:
        plt.colorbar(im, label=kwargs['colorbar_label'])
    else:
        plt.colorbar(im, label='Power (dB/Hz)')
    plt.xlabel('Time (s)')
    plt.ylabel('Frequency (Hz)')
    return plt.gcf() 
开发者ID:jmxpearson,项目名称:physutils,代码行数:44,代码来源:tf.py

示例12: plot_img

# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_data [as 别名]
def plot_img(img, filename='image.png', xlim=None, ylim=None, title="", xlabel="", ylabel=""):
    #
    if not xlim: xlim = (0, img.shape[1] - 1)
    if not ylim: ylim = (0, img.shape[0] - 1)
    x = numpy.linspace(xlim[0], xlim[1], img.shape[1])
    y = numpy.linspace(ylim[0], ylim[1], img.shape[0])
    #
    fig = plt.figure()
    ax = fig.add_subplot(111)
    im = NonUniformImage(ax, cmap=cm.Greys)#, norm=colo.LogNorm(vmin=.00001))
    im.set_data(x, y, img)
    ax.images.append(im)
    #
    ax.set_xlim(*xlim)
    ax.set_ylim(*ylim)
    if title: ax.set_title(title)
    if xlabel: ax.set_xlabel(xlabel)
    if ylabel: ax.set_ylabel(ylabel)
    #
    plt.show()
    plt.savefig(filename)
开发者ID:creasyw,项目名称:humming,代码行数:23,代码来源:figure.py

示例13: plot_stacked_time_series_image

# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_data [as 别名]
    def plot_stacked_time_series_image(self, fig, ax, x, y, z, title='', ylabel='',
                                       cbar_title='', title_font={}, axis_font={}, tick_font = {},
                                       **kwargs):
        '''
        This plot is a stacked time series that uses NonUniformImage with regualrly spaced ydata from
        a linear interpolation. Designed to support FRF ADCP data.
        '''

        if not title_font:
            title_font = title_font_default
        if not axis_font:
            axis_font = axis_font_default
        # z = np.ma.array(z, mask=np.isnan(z))

        h = NonUniformImage(ax, interpolation='bilinear', extent=(min(x), max(x), min(y), max(y)),
                            cmap=plt.cm.jet)
        h.set_data(x, y, z)
        ax.images.append(h)
        ax.set_xlim(min(x), max(x))
        ax.set_ylim(min(y), max(y))
        # h = plt.pcolormesh(x, y, z, shading='gouraud', **kwargs)
        # h = plt.pcolormesh(x, y, z, **kwargs)
        if ylabel:
            ax.set_ylabel(ylabel, **axis_font)
        if title:
            ax.set_title(title, **title_font)
        # plt.axis('tight')
        ax.xaxis_date()
        date_list = mdates.num2date(x)
        self.get_time_label(ax, date_list)
        fig.autofmt_xdate()
        # if invert:
        ax.invert_yaxis()
        cbar = plt.colorbar(h)
        if cbar_title:
            cbar.ax.set_ylabel(cbar_title, **axis_font)

        ax.grid(True)
        if tick_font:
            ax.tick_params(**tick_font)
开发者ID:Bobfrat,项目名称:ooi-ui-services,代码行数:42,代码来源:plot_tools.py

示例14: plot2d

# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_data [as 别名]
def plot2d(x, y, z, ax=None, cmap='RdGy', norm=None, **kw):
    """ Plot dataset using NonUniformImage class

    Parameters
    ----------
    x : (nx,)
    y : (ny,)
    z : (nx,nz)
        
    """
    from matplotlib.image import NonUniformImage
    if ax is None:
        fig = plt.gcf()
        ax = fig.add_subplot(111)

    xlim = (x.min(), x.max())
    ylim = (y.min(), y.max())

    im = NonUniformImage(ax,
                         interpolation='bilinear',
                         extent=xlim + ylim,
                         cmap=cmap)

    if norm is not None:
        im.set_norm(norm)

    im.set_data(x, y, z, **kw)
    ax.images.append(im)
    #plt.colorbar(im)
    ax.set_xlim(xlim)
    ax.set_ylim(ylim)

    def update(z):
        return im.set_data(x, y, z, **kw)

    return im, update
开发者ID:nbren12,项目名称:gnl,代码行数:38,代码来源:plots.py

示例15: NonUniformImage

# 需要导入模块: from matplotlib.image import NonUniformImage [as 别名]
# 或者: from matplotlib.image.NonUniformImage import set_data [as 别名]
x = np.linspace(-4, 4, 9)

# Highly nonlinear x array:
x2 = x**3

y = np.linspace(-4, 4, 9)

z = np.sqrt(x[np.newaxis, :]**2 + y[:, np.newaxis]**2)

fig, axs = plt.subplots(nrows=2, ncols=2)
fig.subplots_adjust(bottom=0.07, hspace=0.3)
fig.suptitle('NonUniformImage class', fontsize='large')
ax = axs[0, 0]
im = NonUniformImage(ax, interpolation=interp, extent=(-4, 4, -4, 4),
                     cmap=cm.Purples)
im.set_data(x, y, z)
ax.images.append(im)
ax.set_xlim(-4, 4)
ax.set_ylim(-4, 4)
ax.set_title(interp)

ax = axs[0, 1]
im = NonUniformImage(ax, interpolation=interp, extent=(-64, 64, -4, 4),
                     cmap=cm.Purples)
im.set_data(x2, y, z)
ax.images.append(im)
ax.set_xlim(-64, 64)
ax.set_ylim(-4, 4)
ax.set_title(interp)

interp = 'bilinear'
开发者ID:4over7,项目名称:matplotlib,代码行数:33,代码来源:image_nonuniform.py


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