会上讨论了能否将校正数据编成序列的问题。 我看不出任何报道都提到这个问题,甚至被接纳为目标。 因此,如果你试图将电线上电离层,显然会失败。 我在搜索时发现的讨论表明,目前使用的配对物设计很容易满足这一目标,这就要求内部进行重组。 参考:rel=“nofollow”http://old.nabble.com/matplotlib-figure-serialization-td28016714.html。
为了大幅缩短执行时间,你可以做的是,将你的数据重新整理成数据集,只读到ax.bar(<>
)。 然后,数据集可以按你想要的任何格式(例如,以超标方式)加以分类和储存。
这里是显示你的做法与将这种做法合并成数据集的守则实例。 如果你想要的话,你可以更容易地看到:。
import matplotlib.pyplot as plt
from random import randint
from time import time
DATA = [
(i, randint(5,30), randint(5,30), randint(30,35), randint(1,5))
for i in xrange(1, 401)
]
def mapValues(group):
ind, open_, close, high, low = group
if open_ > close: # if open is higher then close
height = open_ - close # heigth is drawn at bottom+height
bottom = close
yerr = (open_ - low, high - open_)
color = r # plot as a white barr
else:
height = close - open_ # heigth is drawn at bottom+height
bottom = open_
yerr = (close - low, high - close)
color = g # plot as a black bar
return (ind, height, bottom, yerr, color)
#
# Test 1
#
def test1():
fig = plt.figure()
ax = fig.add_subplot(111)
data = map(mapValues, DATA)
start = time()
for group in data:
ind, height, bottom, yerr, color = group
ax.bar(left=ind, height=height, bottom=bottom, yerr=zip(yerr),
color=color, ecolor= k , zorder=10,
error_kw={ barsabove : False, zorder : 0, capsize : 0},
alpha=1)
return time()-start
#
# Test 2
#
def test2():
fig = plt.figure()
ax = fig.add_subplot(111)
# plotData can be serialized
plotData = zip(*map(mapValues, DATA))
ind, height, bottom, yerr, color = plotData
start = time()
ax.bar(left=ind, height=height, bottom=bottom, yerr=zip(*yerr),
color=color, ecolor= k , zorder=10,
error_kw={ barsabove : False, zorder : 0, capsize : 0},
alpha=1)
return time()-start
def doTest(fn):
end = fn()
print "%s - Sec: %0.3f, ms: %0d" % (fn.__name__, end, end*1000)
if __name__ == "__main__":
doTest(test1)
doTest(test2)
# plt.show()
成果:
python plot.py
test1 - Sec: 1.592, ms: 1592
test2 - Sec: 0.358, ms: 357