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


Python pyplot.draw函数代码示例

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


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

示例1: test_contains

def test_contains():
    import matplotlib.backend_bases as mbackend

    fig = plt.figure()
    ax = plt.axes()

    mevent = mbackend.MouseEvent(
        'button_press_event', fig.canvas, 0.5, 0.5, 1, None)

    xs = np.linspace(0.25, 0.75, 30)
    ys = np.linspace(0.25, 0.75, 30)
    xs, ys = np.meshgrid(xs, ys)

    txt = plt.text(
        0.48, 0.52, 'hello world', ha='center', fontsize=30, rotation=30)
    # uncomment to draw the text's bounding box
    # txt.set_bbox(dict(edgecolor='black', facecolor='none'))

    # draw the text. This is important, as the contains method can only work
    # when a renderer exists.
    plt.draw()

    for x, y in zip(xs.flat, ys.flat):
        mevent.x, mevent.y = plt.gca().transAxes.transform_point([x, y])
        contains, _ = txt.contains(mevent)
        color = 'yellow' if contains else 'red'

        # capture the viewLim, plot a point, and reset the viewLim
        vl = ax.viewLim.frozen()
        ax.plot(x, y, 'o', color=color)
        ax.viewLim.set(vl)
开发者ID:RealGeeks,项目名称:matplotlib,代码行数:31,代码来源:test_text.py

示例2: plot

 def plot(self):
     if self.pos == None:
         self.pos = nx.graphviz_layout(self)
     NODE_SIZE = 500
     plt.clf()
     nx.draw_networkx_nodes(self, pos=self.pos,
                            nodelist=self.normal,
                            node_color=NORMAL_COLOR,
                            node_size=NODE_SIZE)
     nx.draw_networkx_nodes(self, pos=self.pos,
                            nodelist=self.contam,
                            node_color=CONTAM_COLOR,
                            node_size=NODE_SIZE)
     nx.draw_networkx_nodes(self, pos=self.pos,
                            nodelist=self.immune,
                            node_color=IMMUNE_COLOR,
                            node_size=NODE_SIZE)
     nx.draw_networkx_nodes(self, pos=self.pos,
                            nodelist=self.dead,
                            node_color=DEAD_COLOR,
                            node_size=NODE_SIZE)
     nx.draw_networkx_edges(self, pos=self.pos,
                            edgelist=self.nondead_edges(),
                            width=2,
                            edge_color='0.2')
     nx.draw_networkx_labels(self, pos=self.pos,
                             font_color='0.95', font_size=11)
     plt.gca().get_xaxis().set_visible(False)
     plt.gca().get_yaxis().set_visible(False)
     plt.draw()
开发者ID:3lectrologos,项目名称:sna,代码行数:30,代码来源:diffuse.py

示例3: _plot_histogram

 def _plot_histogram(self, data, number_of_devices=1, 
         preamp_timeout=1253):
     if number_of_devices == 0:
         return
     data = np.array(data)
     plt.figure(3)
     plt.ioff()
     plt.get_current_fig_manager().window.wm_geometry("800x550+700+25")
     plt.clf()
     if number_of_devices == 1: 
         plt.hist(data[0,:], bins=preamp_timeout, range=(1, preamp_timeout-1),
             color='b')
     elif number_of_devices == 2:
         plt.hist(data[0,:], bins=preamp_timeout, range=(1, preamp_timeout-1),
             color='r', label='JPM A')
         plt.hist(data[1,:], bins=preamp_timeout, range=(1, preamp_timeout-1),
             color='b', label='JPM B')
         plt.legend()
     elif number_of_devices > 2:
         raise Exception('Histogram plotting for more than two ' +
         'devices is not implemented.')
     plt.xlabel('Timing Information [Preamp Time Counts]')
     plt.ylabel('Counts')
     plt.xlim(0, preamp_timeout)
     plt.draw()
     plt.pause(0.05)
开发者ID:McDermott-Group,项目名称:LabRAD,代码行数:26,代码来源:jpm_qubit_experiments.py

示例4: plotFFT

	def plotFFT(self):
	# Generates plot of the FFT output. To view, run plotFFT.py in a separate terminal
		figure1 = plt.figure(num= None, figsize=(12,12), dpi=80, facecolor='w', edgecolor='w')
		plot1 = figure1.add_subplot(111)
		line1, = plot1.plot( np.arange(0,512,0.5), np.zeros(1024), 'g-')
		plt.xlabel('freq (MHz)',fontsize = 12)
		plt.ylabel('Amplitude',fontsize = 12)
		plt.title('Pre-mixer FFT',fontsize = 12)
		plt.xticks(np.arange(0,512,50))
		plt.xlim((0,512))
		plt.grid()
		plt.show(block = False)
		count = 0 
		stop = 1.0e6
		while(count < stop):
			overflow = np.fromstring(self.fpga.read('overflow', 4), dtype = '>B')
			print overflow
			self.fpga.write_int('fft_snap_ctrl',0)
			self.fpga.write_int('fft_snap_ctrl',1)
			fft_snap = (np.fromstring(self.fpga.read('fft_snap_bram',(2**9)*8),dtype='>i2')).astype('float')
			I0 = fft_snap[0::4]
			Q0 = fft_snap[1::4]
			I1 = fft_snap[2::4]
			Q1 = fft_snap[3::4]
			mag0 = np.sqrt(I0**2 + Q0**2)
			mag1 = np.sqrt(I1**2 + Q1**2)
			fft_mags = np.hstack(zip(mag0,mag1))
			plt.ylim((0,np.max(fft_mags) + 300.))
			line1.set_ydata((fft_mags))
			plt.draw()
			count += 1
开发者ID:braddober,项目名称:blastfirmware,代码行数:31,代码来源:blastfirmware_dirfile.py

示例5: task1

def task1():
    '''demonstration'''
    
    #TASK 0: Demo
    L = 1000 #length, using boundary condition u(x+L)=u(x)
    dx = 1.
    dt = 0.1
    t_max = 100
    c = +10
    
    b = (c*dt/dx)**2
    
    #init fields
    x = arange(0,L+dx/2.,dx) #[0, .... , L], consider 0 = L

    #starting conditions
    field_t = exp(-(x-10)**2) #starting condition at t0
    field_tmdt = exp(-(x-c*dt-10)**2) #starting condition at t0-dt
    
    eq1 = wave_eq(field_t, field_tmdt, b)
    
    plt.ion()
    plot, = plt.plot(x, field_t)
    
    for t in arange(0,t_max,dt):
        print 'outer loop, t=',t
        eq1.step()
        plot.set_ydata(eq1.u)
        plt.draw()
开发者ID:RafiKueng,项目名称:Intro-To-Comp.-Physics,代码行数:29,代码来源:waveeq.py

示例6: draw_window

def draw_window():
    mutex.acquire()
    plt.clf()
    ax = plt.subplot(1,1,1)
    ax.plot(ub_times, ub_points, label = "Upper Bound"  )
    ax.plot(lb_times, lb_points, label = "Lower Bound"  )
    ax.plot(corrected_points_times, corrected_points, label="Estimate")
    ax.plot(ub_times_matched, ub_points_matched, label="Matched Upper Bound")


    p_ub = plt.Rectangle((0, 1), 1, 10, fc="b")
    p_lb = plt.Rectangle((0, 0), 1, 1, fc="g")
    p_c  = plt.Rectangle((0, 0), 1, 1, fc="r")
    p_m  = plt.Rectangle((0, 0), 1, 1, fc="c")

    plt.legend([p_ub , p_lb, p_c, p_m ], ["Upper Bound","Lower Bound" , "Estimate","Mattched Upper Bound"],2)

    #l = plt.legend(bbox_to_anchor=(0, 0, 1, 1), bbox_transform=gcf().transFigure)
    #plt.legend([p_ub, p_lb, p_c], ["Upper Bound", "Lower Bound", "Estimate"])
    global device_clock_id, local_clock_id
    title = "Clock Mapping from %s to %s" % (device_clock_id, local_clock_id)
    plt.title( title)
    plt.ylabel('Offset (ms)')
    plt.xlabel('Device Time (s)')

    plt.draw()
    mutex.release()
开发者ID:andre-nguyen,项目名称:trigger_sync,代码行数:27,代码来源:plot_clock.py

示例7: __init__

 def __init__(self, xv, yv, mask, **kwargs):
     assert xv.shape == yv.shape, 'xv and yv must have the same shape'
     for dx, dq in zip(xv.shape, mask.shape):
          assert dx==dq+1, \
          '''xv and yv must be cell verticies
          (i.e., one cell bigger in each dimension)'''
     
     self.xv = xv
     self.yv = yv
     
     self.mask = mask
     
     land_color = kwargs.pop('land_color', (0.6, 1.0, 0.6))
     sea_color = kwargs.pop('sea_color', (0.6, 0.6, 1.0))
     
     cm = plt.matplotlib.colors.ListedColormap([land_color, sea_color], 
                                              name='land/sea')
     self._pc = plt.pcolor(xv, yv, mask, cmap=cm, vmin=0, vmax=1, **kwargs)
     self._xc = 0.25*(xv[1:,1:]+xv[1:,:-1]+xv[:-1,1:]+xv[:-1,:-1])
     self._yc = 0.25*(yv[1:,1:]+yv[1:,:-1]+yv[:-1,1:]+yv[:-1,:-1])
     
     if isinstance(self.xv, np.ma.MaskedArray):
         self._mask = mask[~self._xc.mask]
     else:
         self._mask = mask.flatten()
     
     plt.connect('button_press_event', self._on_click)
     plt.connect('key_press_event', self._on_key)
     self._clicking = False
     plt.title('Editing %s -- click "e" to toggle' % self._clicking)
     plt.draw()
开发者ID:jingzhiyou,项目名称:octant,代码行数:31,代码来源:grid.py

示例8: accuracy

def accuracy(target, prediction, label="Classifier", c=np.zeros((0,0))):
    correct = (target == prediction)
    correct = np.array((correct, correct))
    compare = np.array((target, prediction))
    
    showC = c != np.zeros((0,0))
    
    if (showC):
        fig, (ax1, ax2, ax3) = plt.subplots(nrows=3, figsize=(6,10))
    else:
        fig, (ax1, ax2) = plt.subplots(nrows=2, figsize=(6,8))
    
    dim = [0,compare.shape[1],0,compare.shape[0]]
    ax1.imshow(compare, extent=dim, aspect='auto', interpolation='nearest')
    ax1.set_title(label + ": Prediction vs. Target")
    
    imgPlt = ax2.imshow(correct, extent=dim, aspect='auto', interpolation='nearest')
    imgPlt.set_cmap('RdYlGn')
    ax2.set_title(label + " Prediction Accuracy")
    
    if (showC):
        ax3.plot(c)
        ax3.set_title("Concentration")
        ax3.set_yscale('log')
        ax3.set_ylim(0.02,0.7)
    
    plt.draw()
开发者ID:mwalton,项目名称:artificial-olfaction,代码行数:27,代码来源:plots.py

示例9: main

def main():
    conn = krpc.connect()
    vessel = conn.space_center.active_vessel
    streams = init_streams(conn,vessel)
    print vessel.control.throttle
    plt.axis([0, 100, 0, .1])
    plt.ion()
    plt.show()

    t0 = time.time()
    timeSeries = []
    vessel.control.abort = False
    while not vessel.control.abort:

        t_now = time.time()-t0
        tel = Telemetry(streams,t_now)
        timeSeries.append(tel)
        timeSeriesRecent = timeSeries[-40:]

        plt.cla()
        plt.semilogy([tel.t for tel in timeSeriesRecent], [norm(tel.angular_velocity) for tel in timeSeriesRecent])
        #plt.semilogy([tel.t for tel in timeSeriesRecent[1:]], [quat_diff_test(t1,t2) for t1,t2 in zip(timeSeriesRecent,timeSeriesRecent[1:])])
        #plt.axis([t_now-6, t_now, 0, .1])
        plt.draw()
        plt.pause(0.0000001)
        #time.sleep(0.0001)

    with open('log.json','w') as f:
        f.write(json.dumps([tel.__dict__ for tel in timeSeries],indent=4))

    print 'The End'
开发者ID:janismac,项目名称:SmallProjects,代码行数:31,代码来源:main.py

示例10: on_keypress

	def on_keypress(self,event):
		global colmax
		global colmin
		if event.key in ['1', '2', '3', '4', '5', '6', '7','8', '9', '0']:
			if not os.path.exists(write_dir + runtag):
				os.mkdir(write_dir + runtag)
			recordtag = write_dir + runtag + "/" + runtag + "_" + event.key + ".txt"
			print "recording filename in " + recordtag
			f = open(recordtag, 'a+')
			f.write(self.filename+"\n")
			f.close()
		if event.key == 'p':
			if not os.path.exists(write_dir + runtag):
				os.mkdir(write_dir + runtag)
			pngtag = write_dir + runtag + "/%s.png" % (self.filename)	
			print "saving image as " + pngtag 
			P.savefig(pngtag)
		if event.key == 'e':
			if not os.path.exists(write_dir + runtag):
				os.mkdir(write_dir + runtag)
			epstag = write_dir + runtag + "/%s.eps" % (self.filename)	
			print "saving image as " + epstag 
			P.savefig(epstag, format='eps')
		if event.key == 'r':
			colmin = self.inarr.min()
			colmax = self.inarr.max()
			P.clim(colmin, colmax)
			P.draw()
开发者ID:sellberg,项目名称:cheetah,代码行数:28,代码来源:viewRun.py

示例11: restart

def restart(arg):
    global collection, all_lines, all_nodes, points, done, nodes_ip4s, nodes_ip6s, lats, lons, cities, xys, colors
    if done:
        return
    for l in all_lines:
        l.remove()
        del l
    all_lines = []
    all_nodes = NodeSet()
    nodes_ip4s = {}
    nodes_ip6s = {}
    lats = []
    lons = []
    cities=[]
    xys = []
    colors = []
    if collection:
        collection.remove()
        del collection
        collection = None
    for p in points:
        p.remove()
        del p
    points = []

    print(arg)
    start_h = InfoHash()
    start_h.setBit(159, 1)
    step(start_h, 0)
    plt.draw()
开发者ID:savoirfairelinux,项目名称:opendht,代码行数:30,代码来源:scanner.py

示例12: demo

def demo():

    fig1 = plt.figure(1, (6, 6))
    fig1.clf()

    # PLOT 1
    # simple image & colorbar
    ax = fig1.add_subplot(2, 2, 1)
    demo_simple_image(ax)

    # PLOT 2
    # image and colorbar whose location is adjusted in the drawing time.
    # a hard way

    demo_locatable_axes_hard(fig1)

    # PLOT 3
    # image and colorbar whose location is adjusted in the drawing time.
    # a easy way

    ax = fig1.add_subplot(2, 2, 3)
    demo_locatable_axes_easy(ax)

    # PLOT 4
    # two images side by side with fixed padding.

    ax = fig1.add_subplot(2, 2, 4)
    demo_images_side_by_side(ax)

    plt.draw()
    plt.show()
开发者ID:KevKeating,项目名称:matplotlib,代码行数:31,代码来源:demo_axes_divider.py

示例13: catchPotentiometry

def catchPotentiometry(ser, PGA_gain):
    i = 0
    voltage = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    t = ["0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0","0:0"]
    pH = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
    
    while True:
        line = ser.readline()
        if line == b'@DONE\n':
            print('Experiment complete')
            break
        elif line == b'B\n':
            pass
        else:
            try:
                s, ms, v = struct.unpack('<HHix', line)
                v = ADCtomV(v, PGA_gain)
                voltage.append(v)
                pH.append(0.0169*v+6.9097)
                t.append("{}:{}".format(s,ms))
                plt.clf()
                plt.plot(pH[-50:-1])
                plt.draw()
                plt.pause(0.00000001)
            except:
                pass
开发者ID:nfroehberg,项目名称:GlazerLab_KStat,代码行数:26,代码来源:KStat_0_1_froehberg_driver.py

示例14: draw

def draw(ord_l, gaps):

    axScatter = plt.subplot(3, 1, 1)

    number_samples=0
    # axScatter.scatter([i['seq'] for i in ord_l[-number_samples:]], [i['a'] for i in ord_l[-number_samples:]], s=2, color='r', label='ch1')
    axScatter.scatter([i['seq'] % 24 for i in ord_l[-number_samples:]], [i['d'] for i in ord_l[-number_samples:]], s=2, color='r', label='ch1')
    # axScatter.scatter(time_l[-number_samples:], b_l[-number_samples:], s=2, color='c', label='ch2')
    # axScatter.scatter(time_l[-number_samples:], c_l[-number_samples:], s=2, color='y', label='ch3')
    # axScatter.scatter(time_l[-number_samples:], d_l[-number_samples:], s=2, color='g', label='ch4')
    plt.ylim(-9000000, 9000000)
    plt.legend()
    axScatter.set_xlabel("Sequence Packet")
    axScatter.set_ylabel("Voltage")
    plt.title("Channels Values")


    # time_plot = plt.subplot(3, 1, 2)
    # time_plot.scatter([i['seq'] for i in ord_l[-number_samples:]], [i['delta'] for i in ord_l[-number_samples:]], s=1, color='r', label='delta')
    # time_plot.set_xlabel("Sequence Packet")
    # time_plot.set_ylabel("Delta to referencial")
    # ax2 = time_plot.twinx()
    # ax2.scatter([i['seq'] for i in ord_l[-number_samples:]], [i['ts'] for i in ord_l[-number_samples:]], s=2, color='g', label='Timestamp')
    # ax2.set_ylabel("Kernel time")
    # plt.title("Timestamp deltas")

    gaps_draw = plt.subplot(3, 1, 3)
    gaps_draw.plot([i[0] for i in gaps[-number_samples:]], [i[1] for i in gaps[-number_samples:]], color='b', marker='.', label='gaps')
    gaps_draw.set_ylim(-0.5, 1.5)

    plt.draw()
    # plt.savefig("res.png")
    plt.show()
开发者ID:cnm,项目名称:miavita-monitor,代码行数:33,代码来源:c.py

示例15: write

  def write(self, timestamps, actualValues, predictedValues,
            predictionStep=1):

    assert len(timestamps) == len(actualValues) == len(predictedValues)

    # We need the first timestamp to initialize the lines at the right X value,
    # so do that check first.
    if not self.linesInitialized:
      self.initializeLines(timestamps)

    for index in range(len(self.names)):
      self.dates[index].append(timestamps[index])
      self.convertedDates[index].append(date2num(timestamps[index]))
      self.actualValues[index].append(actualValues[index])
      self.predictedValues[index].append(predictedValues[index])

      # Update data
      self.actualLines[index].set_xdata(self.convertedDates[index])
      self.actualLines[index].set_ydata(self.actualValues[index])
      self.predictedLines[index].set_xdata(self.convertedDates[index])
      self.predictedLines[index].set_ydata(self.predictedValues[index])

      self.graphs[index].relim()
      self.graphs[index].autoscale_view(True, True, True)

    plt.draw()
    plt.legend(('actual','predicted'), loc=3)
开发者ID:007alibabas,项目名称:nupic,代码行数:27,代码来源:nupic_output.py


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