如何让python matplotlib刷新所有图形

2024-10-02 08:22:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我在玩一些大数据集,这些数据集随着我可以控制的某个参数的函数而变化。 现在我想在同一个图的子图中绘制数据的分布。然而,由于构造直方图需要很大的数据。在

所以,我希望子图,因为他们完成了一点像下面。在

import matplotlib.pyplot as plt
import numpy as np
import numpy.random as npr

Ne=10
MC=1000000
f1d,f2d = plt.figure(),plt.figure()
for Part in range(Ne):
    datax=npr.normal(size=MC)+4*Part/Ne ##Simulates my big data
    datay=npr.normal(size=MC) ##Simulates my big data
    ###The 1d histogram
    sf1d = f1d.add_subplot(1,Ne,Part+1,)    
    sf1d.hist(datax,bins=20,normed=True,histtype='stepfilled',alpha=0.5)
    sf1d.hist(datay,bins=20,normed=True,histtype='stepfilled',alpha=0.5)
    plt.show(block=False)

    ###Some flush argument()

    ###The 2d histogram
    sf2d = f2d.add_subplot(1,Ne,Part+1)
    sf2d.hist2d(datax,datay,bins=20,normed=True)
    plt.show(block=False)

    ###Some flush argument()

但是,python不会实时绘制所有的子图,而是缓冲这些子图,直到循环完成。 如何强制matplotlib立即刷新子图?在


Tags: 数据importtrueas绘制pltmcne
1条回答
网友
1楼 · 发布于 2024-10-02 08:22:10

^{} docs

matplotlib.pyplot.draw()

Redraw the current figure.

This is used in interactive mode to update a figure that has been altered, but not automatically re-drawn.

A more object-oriented alternative, given any Figure instance, fig, that was created using a pyplot function, is:

fig.canvas.draw_idle()

相关问题 更多 >

    热门问题