我想创建一个直方图并保存到一个文件中,而不在屏幕上显示它。我现在拥有的代码在默认情况下是显示图形的,我无法找到任何方法来抑制显示图形。我也试过pyplot.hist(nrs),有同样的问题。
import math, time, matplotlib.pyplot as plt, pylab;
import numpy as np;
nrs = [1.0, 2.0, 1.0, 3.0, 4.0]
freq,bins = np.histogram(nrs)
fig = plt.figure(figsize=(5,4), dpi=100);
freq = np.append(freq, [0.0])
graph = fig.add_subplot(111);
x = graph.bar(bins, freq)
fig.savefig( "test.png")
谢谢你,Tcaswell,加上
在导入pyplot之前解决了这个问题。
相关问题 更多 >
编程相关推荐