matplotlib中每个图的唯一图标记

matplotlib中每个图的唯一图标记,第1张

matplotlib中每个图的唯一图标记

itertools.cycle
无限期遍历列表或元组。此功能优于为您随机选择标记的功能。

Python 2.x
import itertoolsmarker = itertools.cycle((',', '+', '.', 'o', '*')) for n in y:    plt.plot(x,n, marker = marker.next(), linestyle='')
Python 3.x
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()



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5650770.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存