itertools.cycle将无限期地遍历列表或元组。此功能优于为您随机选择标记的功能。Python 2.x
Python 3.ximport itertoolsmarker = itertools.cycle((',', '+', '.', 'o', '*')) for n in y: plt.plot(x,n, marker = marker.next(), linestyle='')
import itertoolsmarker = itertools.cycle((',', '+', '.', 'o', '*')) for n in y: plt.plot(x,n, marker = next(marker), linestyle='')
您可以使用它来生成如下图(Python 2.x):
import numpy as npimport matplotlib.pyplot as pltimport itertoolsx = np.linspace(0,2,10)y = np.sin(x)marker = itertools.cycle((',', '+', '.', 'o', '*'))fig = plt.figure()ax = fig.add_subplot(111)for q,p in zip(x,y): ax.plot(q,p, linestyle = '', marker=marker.next())plt.show()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)