python – 使用循环变量在matplotlib中指定颜色

python – 使用循环变量在matplotlib中指定颜色,第1张

概述我有很多数据文件,我想在同一个图上绘制所有数据,但颜色不同.我使用以下代码 from pylab import loadtxt, average, std, argsortfrom os import listdirfrom fnmatch import fnmatchimport matplotlib.pyplot as plta=[]for file in listdir('.' 我有很多数据文件,我想在同一个图上绘制所有数据,但颜色不同.我使用以下代码

from pylab import loadtxt,average,std,argsortfrom os import Listdirfrom fnmatch import fnmatchimport matplotlib.pyplot as plta=[]for file in Listdir('.'):   if fnmatch(file,'A10data*'):      a+=[str(file)]for file in a:  T,m_abs,m_abs_err,m_phy,m_phy_err = loadtxt(file,unpack=True)  T_sort = argsort(T)  plt.xlim(0.00009,10.1)  plt.ylim(-1,350)  plt.semilogx(T[T_sort],m_abs[T_sort],'ro-')  plt.errorbar(T[T_sort],yerr=m_abs_err[T_sort],fmt='ro')  plt.semilogx(T[T_sort],m_phy[T_sort],'r^-')  plt.errorbar(T[T_sort],yerr=m_phy_err[T_sort],fmt='r^')plt.show()

可能我可以使用整数并使用整数来指定绘图的颜色.有人可以帮我解释语法吗?

解决方法 如果文件/图的数量很小,你可以制作一个颜色数组,其长度与上面的数组相同:类似于:

colors = ["red","blue","green","orange","purple"]ncolor = 0for file in a:    plt.semilogx(T[T_sort],'o-',color=colors[ncolor])    ncolor+=1
总结

以上是内存溢出为你收集整理的python – 使用循环变量在matplotlib中指定颜色全部内容,希望文章能够帮你解决python – 使用循环变量在matplotlib中指定颜色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

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

原文地址: https://outofmemory.cn/langs/1196641.html

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

发表评论

登录后才能评论

评论列表(0条)

保存