我在重新画这个人物的时候遇到了问题.我允许用户指定时间刻度(x轴)中的单位,然后重新计算并调用此函数plots().我想简单地更新绘图,而不是将另一个绘图附加到图中.

def plots():
    global vlgaBuffSorted
    cntr()

    result = collections.defaultdict(list)
    for d in vlgaBuffSorted:
        result[d['event']].append(d)

    result_list = result.values()

    f = Figure()
    graph1 = f.add_subplot(211)
    graph2 = f.add_subplot(212,sharex=graph1)

    for item in result_list:
        tL = []
        vgsL = []
        vdsL = []
        isubL = []
        for dict in item:
            tL.append(dict['time'])
            vgsL.append(dict['vgs'])
            vdsL.append(dict['vds'])
            isubL.append(dict['isub'])
        graph1.plot(tL,vdsL,'bo',label='a')
        graph1.plot(tL,vgsL,'rp',label='b')
        graph2.plot(tL,isubL,'b-',label='c')

    plotCanvas = FigureCanvasTkAgg(f, pltFrame)
    toolbar = NavigationToolbar2TkAgg(plotCanvas, pltFrame)
    toolbar.pack(side=BOTTOM)
    plotCanvas.get_tk_widget().pack(side=TOP)

推荐答案

您基本上有两种 Select :

  1. 做你现在正在做的事,但是在重新绘制数据之前拨打graph1.clear()graph2.clear().这是最慢的,但也是最简单、最健壮的 Select .

  2. 可以只更新打印对象的数据,而不需要重新打印.您需要对代码进行一些更改,但这应该比每次重新打印要快得多.但是,您正在绘制的数据的形状不能更改,如果您的数据范围正在更改,则需要手动重置x和y轴限制.

举一个第二种 Select 的例子:

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 6*np.pi, 100)
y = np.sin(x)

# You probably won't need this if you're embedding things in a tkinter plot...
plt.ion()

fig = plt.figure()
ax = fig.add_subplot(111)
line1, = ax.plot(x, y, 'r-') # Returns a tuple of line objects, thus the comma

for phase in np.linspace(0, 10*np.pi, 500):
    line1.set_ydata(np.sin(x + phase))
    fig.canvas.draw()
    fig.canvas.flush_events()

Python相关问答推荐

如何列出Python脚本中使用的所有包?

跳过包含某些键的字典

是否有使用纯霍夫曼编码的现代图像格式?

如何分割我的收件箱,以便连续的数字各自位于自己的收件箱中?

Django文件上传不起作用:文件未出现在媒体目录或数据库中

将词典写入Excel

Google Drive API获取文件计量数据

跟踪我已从数组中 Select 的样本的最有效方法

如何从FDaGrid实例中删除某些函数?

如何使用Google Gemini API为单个提示生成多个响应?

如何使用matplotlib在Python中使用规范化数据和原始t测试值创建组合热图?

为什么符号没有按顺序添加?

从groupby执行计算后创建新的子框架

在Python argparse包中添加formatter_class MetavarTypeHelpFormatter时, - help不再工作""""

实现自定义QWidgets作为QTimeEdit的弹出窗口

Scrapy和Great Expectations(great_expectations)—不合作

使用Python从URL下载Excel文件

Python中的变量每次增加超过1

考虑到同一天和前2天的前2个数值,如何估算电力时间序列数据中的缺失值?

ConversationalRetrivalChain引发键错误