栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

快速更新图中的单个点

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

快速更新图中的单个点

您实际上忽略了发条所需的大部分功能。见例如

  • 为什么用Matplotlib绘制这么慢?
  • Matplotlib / PyPlot中的快速实时绘图

和往常一样

  • 画画布
    fig.canvas.draw()
  • 保存背景以备后用,
    fig.canvas.copy_from_bbox()
  • 更新要点,
    point.set_data
  • 恢复背景,
    fig.canvas.restore_region
  • 指出要点,
    ax.draw_artist
  • 咬住轴
    fig.canvas.blit

因此

import matplotlib.pyplot as pltimport numpy as npclass Test:    def __init__(self):        self.fig = plt.figure(1)        # Axis with large plot        self.ax_large = plt.subplot(121)        self.ax_large.imshow(np.random.random((5000,5000)))        # Follow the point        self.ax = plt.subplot(122)        self.ax.grid(True)        # set some limits to the axes        self.ax.set_xlim(-5,5)        self.ax.set_ylim(-5,5)        # Draw the canvas once        self.fig.canvas.draw()        # Store the background for later        self.background = self.fig.canvas.copy_from_bbox(self.ax.bbox)        # Now create some point        self.point, = self.ax.plot(0,0, 'go')        # Create callback to mouse movement        self.cid = self.fig.canvas.callbacks.connect('motion_notify_event',          self.callback)        plt.show()    def callback(self, event):        if event.inaxes == self.ax: # Update point's location  self.point.set_data(event.xdata, event.ydata) # Restore the background self.fig.canvas.restore_region(self.background) # draw the point on the screen self.ax.draw_artist(self.point) # blit the axes self.fig.canvas.blit(self.ax.bbox)tt = Test()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/661788.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号