首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Matplotlib multiProcessing

Matplotlib multiProcessing
EN

Stack Overflow用户
提问于 2013-09-14 16:37:58
回答 1查看 1.5K关注 0票数 0

我试图使它能够运行一个无限循环,要求用户输入以及运行一个matplotlib简单图。有什么建议吗?目前,我的代码是:

代码语言:javascript
复制
def createGraph():
 fig = plt.figure()
 fig.suptitle('A Graph ', fontsize=14, fontweight='bold')

 ax = fig.add_subplot(111)
 fig.subplots_adjust(top=.9)

 ax.set_xlabel('X Score')
 ax.set_ylabel('Y Score')
 plt.plot([1,2,3,4,5,6,7],[1,3,3,4,5,6,7], 'ro')
 plt.show()

def sub_proc(q,fileno):
 sys.stdin = os.fdopen(fileno)  #open stdin in this process
 some_str = ""
 while True:
    some_str = raw_input("> ")

    if some_str.lower() == "quit":
        return
    q.put_nowait(some_str)

if __name__ == "__main__":
    q = Queue()
    fn = sys.stdin.fileno() #get original file descriptor
    qproc = Process(target=sub_proc, args=(q,fn))
    qproc.start()
    qproc.join()
    zproc = Process(target=createGraph)
    zproc.start()
    zproc.join()

正如您所看到的,我正在尝试让进程使其工作,因此代码可以并行工作。最终,我想得到它,以便用户可以显示一个图形,同时能够在控制台中输入。谢谢你的帮助!!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-09-14 19:35:14

这是你想要的吗?

代码语言:javascript
复制
import matplotlib.pyplot as plt
import numpy as np

if __name__ == "__main__":
    fig, ax = plt.subplots(1, 1)
    theta = np.linspace(0, 2*np.pi, 1024)
    ln, = ax.plot(theta, np.sin(theta))

    plt.ion()
    plt.show(block=False)
    while True:
        w = raw_input("enter omega: ")
        try:
            w = float(w)
        except ValueError:
            print "you did not enter a valid float, try again"
            continue
        y = np.sin(w * theta)
        ln.set_ydata(y)
        plt.draw()

我想我把你的评论写得太复杂了

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18803960

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档