Python内存泄漏使用Bokeh库进行绘图

时间:2015-09-21 15:54:50

标签: python memory bokeh

我有一个功能,首先从外部文件读取数据,然后使用散景绘制它。问题是,如果我多次使用该函数,它每次都会消耗一点内存,所以一段时间后内存已满。内存是指python使用的内存,而不是显示图形的浏览器。以下代码正在绘制函数内的数据。

w=self.time_diff_calc(time_diff.split("_")[0]+time_diff.split("_")[1])*60*500
colors=["#C93434","#78AD32","#5E6069","#9651DB","","","","","","","","","","",""]

#mids- middle of candlestick, span- height
mids = np.array((data1["open"] + data1["close"])/2)
spans = np.array(abs(data1["close"]-data1["open"]))

#inc- open<close, dec- open>close
inc = data1["close"]>data1["open"]
dec = data1["close"]<data1["open"]

##############the part that eats the memory###################

p = figure(x_axis_type="datetime",plot_width=1200)

data_time=data1["time"]
data_high=data1["high"]
data_low=data1["low"]

p.segment(data_time, data_high, data_time, data_low, color="black")

data_inc=data_time[inc]
data_dec=data_time[dec]
mids_inc=mids[inc]
mids_dec=mids[dec]
spans_inc=spans[inc]
spans_dec=spans[dec]

p.rect(data_inc,mids_inc , w, spans_inc, fill_color="#58AFD1", line_color="black")
p.rect(data_dec, mids_dec, w, spans_dec, fill_color="#FFFFFF", line_color="black")

###########################################################

p.title=self.name
p.grid.grid_line_alpha=0.3
save(p)

0 个答案:

没有答案