[英]Very Slow network graph animation in Python's matplotlib with networkx
[英]MatPlotLib is very slow in python
import matplotlib
matplotlib.use('TkAgg')
def generate_graph(self,subject,target,filename):
x_data = range(0, len(self.smooth_hydro))
mslen = len([i[1] for i in self.master_seq.items()][0])
diff=(mslen-len(self.smooth_hydro))/2
x1_data = range(0,len(self.smooth_groups.items()[0][-1]))
x2_data = range(0,mslen)
plt.figure()
plt.axhline(y=0, color='black')
plt.ylim(-3, 3)
plt.xlim(right=mslen)
plt.plot(x_data, self.smooth_hydro, linewidth=1.0, label="hydrophobicity", color='r')
plt.plot(x_data, self.smooth_amphi, linewidth=1.0, label="amphipathicity", color='g')
for pos in self.hmmtop:
plt.axvline(x=pos-1-diff, ymin=-2, ymax = 0.1, linewidth=1, color='black',alpha=0.2)
plt.axvspan(subject[0]-diff,subject[1]-diff, facecolor="orange", alpha=0.2)
plt.axvspan(target[0]-diff,target[1]-diff, facecolor="orange", alpha=0.2)
plt.legend(loc='upper center', bbox_to_anchor=(0.5, 1.05),
ncol=3, fancybox=True, shadow=True)
plt.xlabel("Residue Number")
plt.ylabel("Value")
width = (0.0265)*len(self.master_seq[0]) if mslen > 600 else 15
plt.grid('on')
plt.savefig(self.out+'/graphs/'+filename+'.png')
plt.clf()
plt.cla()
plt.close()
我反復調用此函數,但是生成的圖像非常慢。 有人可以幫我優化此代碼,使其運行更快嗎?
謝謝!
Matplotlib可以制作出色的出版物質量的圖形,但在速度上沒有很好的優化。 有很多python繪圖軟件包在設計時都考慮了速度:
http://pyqwt.sourceforge.net/ [編輯:pyqwt不再維護;以前的維護者推薦pyqtgraph]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.