模块卡在ipython中的show()上

时间:2016-03-30 02:44:47

标签: python matplotlib ipython show hang

您好我在ipython文本编辑器中创建了一个模块,然后在ipython笔记本中调用它,当我从matplotlib调用show()时它会冻结。我在表面上运行Windows 10.我检查了答案,我发现使用import matplotlib作为mpl mpl.use( 'TkAgg')

在我的模块的开头第一次工作,然后每次我试图在它杀死我的内核后运行。这是我的模块,名为Take_Home.py:

import numpy as np
import matplotlib as mpl
import pdb
#mpl.use('TkAgg')
import matplotlib.pyplot as plt
import matplotlib.mlab as ml

def statistics(array,bin_size):

    #calculate mean and standard deviation of array
    mean=np.mean(array)
    std=np.std(array)

    #get the gaussian fit of the data
    gaussian=ml.normpdf(array,mean,std)

    #plot the normalized histogram
    plt.hist(array,bins=np.arange(np.min(array), np.max(array) + bin_size,  bin_size),normed=True)

    #plot the gaussian function over the histogram
    plt.plot(array,gaussian,'.k')

    #this attempts to show the plot but doesn't work
    plt.show()

    #saves the plot to a PDF
    plt.savefig('Statistics.pdf')

这是调用模块的ipython笔记本:

import Take_Home as th
import numpy as np
import matplotlib.pyplot as plt

#initialize an array of 1000 elements and set them all to 1
rd=np.arange(0,1000)
rd[:]=1

#change the array to have all random numbers with a std of 2 and a mean of 1
rd=rd*(2*np.random.randn(1,1000)+1)

#transpose it because the error message said so
rd=np.transpose(rd)

#declare bin size
binsize=0.2

#use method inside module
th.statistics(rd,binsize)

我只是需要展示情节而且我不知道为什么它会起作用任何帮助都会非常感谢谢谢!

0 个答案:

没有答案