简体   繁体   English

python/pyqt中的交互式实时绘图

[英]Iinteractive real time plotting in python/pyqt

I'm trying to implement an application that plots data in a real time fashion.我正在尝试实现一个以实时方式绘制数据的应用程序。 I have tried some code I found in this question but it doesn't work.我已经尝试了在这个问题中找到的一些代码,但它不起作用。 The figure plots one result before the for loop and one result when the for loop is done该图绘制了for循环之前的一个结果和for循环完成后的一个结果

This is run in Ubuntu, from the Python interpreter.这是在 Ubuntu 中从 Python 解释器运行的。

The code I'm referring to:我指的代码:

import numpy as np
import matplotlib.pyplot as plt

plt.ion()
mu, sigma = 100, 15
fig = plt.figure()
x = mu + sigma*np.random.randn(10000)
n, bins, patches = plt.hist(x, 50, normed=1, facecolor='green', alpha=0.75)
for i in range(50):
    x = mu + sigma*np.random.randn(10000)
    n, bins = np.histogram(x, bins, normed=True)
    for rect,h in zip(patches,n):
        rect.set_height(h)
    fig.canvas.draw()

The problem arises because of the backend.问题出在后端。 I had Qt4Agg and after changing it to TkAgg it worked.. no idea why Qt4Agg didn't worth though...我有Qt4Agg ,在将其更改为TkAgg它起作用了..不知道为什么 Qt4Agg 不值得...

to change the backend i had to edit the /etc/matplotlibrc file要更改后端,我必须编辑 /etc/matplotlibrc 文件

EDIT:编辑:

found information about Qt4Agg instead of calling draw() it should be paused for as long as required by calling pause(0.001) instead, here it is paused for 1ms.找到有关 Qt4Agg 的信息而不是调用draw()应该通过调用pause(0.001)来暂停,只要需要,这里暂停 1ms。

info on this这方面的信息

https://github.com/matplotlib/matplotlib/issues/177 https://github.com/matplotlib/matplotlib/issues/177

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM