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


Python pyplot.stem函数代码示例

本文整理汇总了Python中matplotlib.pyplot.stem函数的典型用法代码示例。如果您正苦于以下问题:Python stem函数的具体用法?Python stem怎么用?Python stem使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: stem_hist

def stem_hist(img, plotTitle):
  import matplotlib.pyplot as plt
  from matplotlib import cm
  imgarray = img.calc_hist()
  plt.figure()
  plt.stem(arange(img.grayLevel), imgarray)
  plt.title(plotTitle)
开发者ID:apvijay,项目名称:image_proc,代码行数:7,代码来源:Img.py

示例2: impz

def impz(b, a=1):
    """Plot step and impulse response of an FIR filter.

    b : float
        Forward terms of the FIR filter.
    a : float
        Feedback terms of the FIR filter. (Default value = 1)

    From http://mpastell.com/2010/01/18/fir-with-scipy/

    Returns
    -------
    None

    """
    l = len(b)
    impulse = np.repeat(0., l)
    impulse[0] = 1.
    x = np.arange(0, l)
    response = sp.lfilter(b, a, impulse)
    plt.subplot(211)
    plt.stem(x, response)
    plt.ylabel('Amplitude')
    plt.xlabel(r'n (samples)')
    plt.title(r'Impulse response')
    plt.subplot(212)
    step = sp.cumsum(response)
    plt.stem(x, step)
    plt.ylabel('Amplitude')
    plt.xlabel(r'n (samples)')
    plt.title(r'Step response')
    plt.subplots_adjust(hspace=0.5)
开发者ID:Lx37,项目名称:pambox,代码行数:32,代码来源:utils.py

示例3: plotstft

def plotstft(sxx, Fs=100):
    winlen = int(len(sxx[0]))

    # with plt.():
    fig1 = plt.figure()
    ax = fig1.add_subplot(1,1,1)
    ctr = int(winlen / 2)
    faxis = np.multiply(Fs / 2, np.linspace(0, 1, ctr))*60
    ratio = []
    for dft in sxx:
        mag = abs(dft[0:ctr])
        max_idx, max_val = max(enumerate(mag), key = lambda p: p[1])
        ptotal = np.square(np.linalg.norm(mag,2))
        pmax = np.square(np.absolute(max_val))
        # print('max power: {}'.format(max_val))
        frac = pmax/ptotal
        # print(frac)
        ratio.append(frac)

        ax.plot(faxis, mag, linewidth=3.0)
        ax.set_xlabel('Frequency (RPM)')
        ax.set_ylabel('|H(f)|')
        ax.set_title('User 4 STFT Spectrum')
        font = {'family' : 'sans-serif ',
                'weight' : 'bold',
                'size'   : 30}
        rc('font', **font)

    fig1.savefig('STFTPlot.png')
    fig2 = plt.figure()
    plt.stem(np.linspace(1,len(ratio),num=len(ratio)),ratio, linewidth=3.0)
    plt.xlabel('Window (10s)', fontsize = 60)
    plt.ylabel('Symmetry in Pedaling', fontsize = 60)
    fig2.savefig('RatioPlot.png')
开发者ID:YoDaMa,项目名称:BikeAnalysis,代码行数:34,代码来源:bikedata.py

示例4: run_OMP

def run_OMP(plot=False, **options):
    """Recover one signal using OMP."""
    n = options.pop('n', 128)
    k = options.pop('k', 5)
    m = options.pop('m', 20)
    dist = options.pop('dist', 'uniform')
    seed = options.pop('seed', None)
    return_locals = options.pop('return_locals', True)

    print ('Recovering signal wiht n=%(n)i, k=%(k)i and m=%(m)i using OMP' %
           locals())

    if seed:
        np.random.seed(seed)
    x = get_sparse_x(n, k, dist=dist)
    if seed:
        np.random.seed(seed + 198)
    A = random_dict(m, n)
    y = np.dot(A, x)

    x_hat, residues, scores, Delta = omp(A, y, save_data=True)

    if plot:
        plt.figure()
        plt.stem(range(n), x, 'r-', 'ro', 'k:')
        plt.stem(range(n), x_hat, 'b:', 'bx', 'k:')
        plt.show()

    print 'error', norm(x - x_hat.reshape(n, 1))

    if return_locals:
        return locals()
开发者ID:aweinstein,项目名称:osomp,代码行数:32,代码来源:osomp.py

示例5: _periodogram_plot

def _periodogram_plot(title, column, data, trend, peaks):
    """display periodogram results using matplotlib"""

    periods, power = periodogram(data)
    plt.figure(1)
    plt.subplot(311)
    plt.title(title)
    plt.plot(data, label=column)
    if trend is not None:
        plt.plot(trend, linewidth=3, label="broad trend")
        plt.legend()
        plt.subplot(312)
        plt.title("detrended")
        plt.plot(data - trend)
    else:
        plt.legend()
        plt.subplot(312)
        plt.title("(no detrending specified)")
    plt.subplot(313)
    plt.title("periodogram")
    plt.stem(periods, power)
    for peak in peaks:
        period, score, pmin, pmax = peak
        plt.axvline(period, linestyle='dashed', linewidth=2)
        plt.axvspan(pmin, pmax, alpha=0.2, color='b')
        plt.annotate("{}".format(period), (period, score * 0.8))
        plt.annotate("{}...{}".format(pmin, pmax), (pmin, score * 0.5))
    plt.tight_layout()
    plt.show()
开发者ID:Lampadina,项目名称:seasonal,代码行数:29,代码来源:application.py

示例6: plotImpulseResponse

    def plotImpulseResponse(self, xmin=None, xmax=None, ymin_imp=None, ymax_imp=None, ymin_step=None, ymax_step=None):
        """Plot the frequency and phase response of the filter object.

      :param xmin: Minimum value for x-axis.
      :param xmax: Maximum value for x-axis.
      :param ymin_imp: Minimum value for y-axis for the impulse response plot.
      :param ymax_imp: Maximum value for y-axis for the impulse response plot.
      :param ymin_step: Minimum value for y-axis for the step response plot.
      :param ymax_step: Maximum value for y-axis for the step response plot.
      """
        #  def plotImpulseResponse(b,a=1):
        l = len(self.ir)
        impulse = np.repeat(0.0, l)
        impulse[0] = 1.0
        x = np.arange(0, l)
        response = sp.signal.lfilter(self.ir, 1, impulse)
        mp.subplot(211)
        mp.stem(x, response)
        mp.ylabel("Amplitude")
        mp.xlabel(r"n (samples)")
        mp.title(r"Impulse response")
        mp.subplot(212)

        step = np.cumsum(response)
        mp.stem(x, step)
        mp.ylabel("Amplitude")
        mp.xlabel(r"n (samples)")
        mp.title(r"Step response")
        mp.subplots_adjust(hspace=0.5)
        mp.show()
开发者ID:bsinglet,项目名称:davitpy,代码行数:30,代码来源:sigproc.py

示例7: moment_ss_shear_bending

def moment_ss_shear_bending(L,Pin,ain):
    '''
    Shear Bending plot of moment loads of a simply supported beam
    L = 4 # total length of beam
    Pin = [5]  # point moment load
    ain = [2]  # location of point load

    # or more multiple point moments
    L = 10
    Pin = [3,-15]
    ain = [2,6]
    '''

    import numpy as np
    import matplotlib.pyplot as plt
    
    x = np.arange(0,L,L*0.02)
    V = np.zeros(len(x))
    M = np.zeros(len(x))
    
    for a, P in zip(ain, Pin):
        V += -P/L
        M[x<=a] += -P*x[x<=a]/L
        M[x>a] += P*(1-x[x>a]/L)    
    
    plt.figure()
    plt.title('Point Moment Loads')
    plt.subplot(2,1,1)    
    plt.stem(x,V)
    plt.ylabel('V,shear')
    plt.subplot(2,1,2)
    plt.stem(x,M)
    plt.ylabel('M,moment')    
开发者ID:GeoZac,项目名称:mechpy,代码行数:33,代码来源:statics.py

示例8: show_ae

def show_ae(autoencoder):
    encoder = autoencoder.Encoder()
    decoder = autoencoder.Decoder()

    encoded_imgs = encoder.predict(X_test)
    decoded_imgs = decoder.predict(encoded_imgs)

    n = 10
    plt.figure(figsize=(20, 6))
    for i in range(n):

        ax = plt.subplot(3, n, i + 1)
        plt.imshow(X_test[i].reshape(28, 28))
        plt.gray()
        ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)

        ax = plt.subplot(3, n, i + 1 + n)
        plt.stem(encoded_imgs[i].reshape(-1))
        plt.gray()
        ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)

        ax = plt.subplot(3, n, i + 1 + n + n)
        plt.imshow(decoded_imgs[i].reshape(28, 28))
        plt.gray()
        ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)

    plt.show()
开发者ID:MoDeep,项目名称:MyoGAN,代码行数:30,代码来源:AE_MNIST.py

示例9: plotVibEpoch

    def plotVibEpoch(self, epochTimes, signal=None, points=False):

        # indStart = int(epochTimes[0] * qu.s * self.entireVibrationSignal.sampling_rate + self.recordingStartIndex)
        # indEnd = int(epochTimes[1] * qu.s * self.entireVibrationSignal.sampling_rate + self.recordingStartIndex)

        # epochTVec = self.entireVibrationSignal.t_start + np.arange(indStart, indEnd) * self.entireVibrationSignal.sampling_period

        # plt.plot(epochTVec, self.entireVibrationSignal[indStart:indEnd], 'g' + extra)

        indStart = int(epochTimes[0] * qu.s * self.vibrationSignalDown.sampling_rate)
        indEnd = int(epochTimes[1] * qu.s * self.vibrationSignalDown.sampling_rate)

        epochTVec = self.vibrationSignalDown.t_start + np.arange(indStart, indEnd) * self.vibrationSignalDown.sampling_period

        stimEnds = (np.array(self.stimEndInds)) / self.downSamplingFactor
        stimStarts = (np.array(self.stimStartInds)) / self.downSamplingFactor

        stimEndsPresent = [x * self.vibrationSignalDown.sampling_period + self.vibrationSignalDown.t_start
                           for x in stimEnds if indStart <= x <= indEnd]
        stimStartsPresent = [x * self.vibrationSignalDown.sampling_period + self.vibrationSignalDown.t_start
                             for x in stimStarts if indStart <= x <= indEnd]

        extra = ''
        if points:
            extra = '*-'

        plt.plot(epochTVec, self.vibrationSignalDown[indStart:indEnd], 'g' + extra)
        plt.stem(stimStartsPresent, np.ones(np.shape(stimStartsPresent)), 'k')
        plt.stem(stimEndsPresent, np.ones(np.shape(stimEndsPresent)), 'm')
        if not signal is None:
            plt.plot(epochTVec, signal[indStart:indEnd], 'r' + extra)

        plt.plot(epochTVec, 2 * self.vibrationSignalDownStdDev * np.ones(epochTVec.shape), 'y')
开发者ID:asobolev,项目名称:GJEMS,代码行数:33,代码来源:rawDataProcess.py

示例10: stemplotf

def stemplotf(v, p):
	fig2=plt.figure()
	fig2.suptitle('Problem 2b: Data Set %s' % p)
	plt.stem(v)
	plt.xlabel('k')
	plt.ylabel('1/E[alpha_k]')
	fig2.savefig('Problem2b_data%s' % p)
开发者ID:afenichel,项目名称:EECS6892BayesianModelsML,代码行数:7,代码来源:Homework3.py

示例11: plot_station_res

def plot_station_res(sta_res,ires,perr=False,scale=1):
    
    titles = ('Tangent Force','Normal Force','Tangent Moment','Normal moment','Inflow Angle','Angle of Attack','Reynolds number',
              'Local vel.','Axial induction','Radial Induction','Effective Velocity','Lift Coeff','Drag Coeff','Loss Factor',
              'CT','CQ','CP','dP','radius','azim','height','ind_vel_a','ind_vel_r')

    axis = get_station_res(sta_res,18)
    res = get_station_res(sta_res,ires)

    axis = np.array(axis) * scale

    #plt.figure()
    if perr is True:
        plt.subplot(211)
        plt.plot(axis,res,'-o')
        plt.subplot(212)
        err = get_station_res(sta_res,-1)
        plt.stem(axis, err, 'r-')
    else:
        plt.figure()
        plt.plot(axis,res,'-o')
    plt.grid()
    plt.title(titles[ires])
    plt.show()

    return 0
开发者ID:simaosr,项目名称:pyWT,代码行数:26,代码来源:Utils.py

示例12: stepplot

def stepplot(x, y, labels, plot_titles):

        """Generates Correlation Graph. 
        With the x,y coordinates, labels, and plot titles
        established, the step-plots can be generated. Output 
        is PDF file format"""

        plt.figure()      #makes new image for each plot  
        
        #plot x & y stemplot. format plot points
        plt.stem(x, y, linefmt='k--', markerfmt='ro', basefmt='k-')               
        
        #set x-axis labels and set them vertical. size 10 font.
        plt.xticks(x, labels, rotation='vertical', fontsize = 10)
              
        #set titles for graph and axes
        plt.title(plot_titles[0])
        plt.xlabel("Biomarkers")
        plt.ylabel("Correlation Values")
        
        # slightly move axis away from plot. prevents clipping the labels 
        plt.margins(0.2)
        
        # Tweak spacing to prevent clipping of tick-labels
        plt.subplots_adjust(bottom=0.15)
        
        plt.tight_layout()   #prevents labels from being clipped
                  

        with PdfPages(plot_titles[0]+'.pdf') as pdf: #creates new file for each figure
            pdf.savefig()
开发者ID:dolleyj,项目名称:flatfile_visualizer,代码行数:31,代码来源:flatfile_visualizer.py

示例13: show_spec_in_graph

def show_spec_in_graph(graph, vertex, spec, pos, weight, file_name):
    dist = 1.0 - squareform(pdist(spec.T, 'cosine'))

    plt.figure()
    plt.stem(dist[vertex, :], markerfmt=' ')

    rim = graph.new_vertex_property('vector<double>')
    rim.set_2d_array(np.array([0, 0, 0, 1]))
    rim[graph.vertex(vertex)] = [0.8941176471, 0.1019607843, 0.1098039216, 1]
    rim_width = graph.new_vertex_property('float', vals=0.5)
    rim_width.a[vertex] = 2
    shape = graph.new_vertex_property('int', vals=0)
    shape[graph.vertex(vertex)] = 2
    size = graph.new_vertex_property('double', vals=10)
    size.a[vertex] = 15
    correlation = graph.new_vertex_property('double', vals=2)
    correlation.a = dist[vertex, :]
    vorder = graph.new_vertex_property('int', vals=0)
    vorder.a[vertex] = 1

    palette = sns.cubehelix_palette(256)
    cmap = colors.ListedColormap(palette)
    gt_draw.graph_draw(graph, pos=pos, vertex_color=rim, vorder=vorder,
                       vertex_pen_width=rim_width,
                       vertex_shape=shape, vertex_fill_color=correlation,
                       vcmap=cmap, vertex_size=size, edge_color=[0, 0, 0, 0.7],
                       edge_pen_width=weight, output=file_name + '.png',
                       output_size=(1200, 1200))

    plt.figure()
    utils.plot_colorbar(cmap, np.arange(0, 1.01, 0.2), file_name)
开发者ID:marianotepper,项目名称:sgft,代码行数:31,代码来源:test_temperatures.py

示例14: graph

	def graph(b,a=1):
			#make a graph
			w,h = signal.freqz(b,a)
			h_dB = 20 * np.log10 (abs(h))
			plt.figure()
			#plt.subplot(311)
			plt.plot(w/max(w),h_dB)
			plt.ylim(-150, 5)
			plt.ylabel('Magnitude (db)')
			plt.xlabel(r'Normalized Frequency (x$\pi$rad/sample)')
			plt.title(r'Frequency response')
			plt.show()
			plt.figure()
			l = len(b)
			impulse = np.repeat(0.,l); impulse[0] =1.
			x = arange(0,l)
			response = signal.lfilter(b,a,impulse)
			#plt.subplot(312)
			plt.stem(x, response)
			plt.ylabel('Amplitude')
			plt.xlabel(r'n (samples)')
			plt.title(r'Impulse response')
			plt.show()
			#plt.figure()
			#plt.subplot(313)
			#step = np.cumsum(response)
			#plt.stem(x, step)
			#plt.ylabel('Amplitude')
			#plt.xlabel(r'n (samples)')
			#plt.title(r'Step response')
			#plt.subplots_adjust(hspace=0.5)
			#plt.show()
			return 1
开发者ID:KasparSnashall,项目名称:FIRfilter,代码行数:33,代码来源:filter.py

示例15: viz_rank

def viz_rank(Oi,k=None):
    if k is None:
        U, s, VT = np.linalg.svd(Oi)
    else:
        U, s, VT = thin_svd_randomized(Oi,k)

    plt.figure()
    plt.stem(np.arange(s.shape[0]),s)
开发者ID:mattjj,项目名称:py4sid,代码行数:8,代码来源:estimation.py


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