python循环变颜色_在Python中使用循环变量在matplotlib中指定颜色
我有很多數(shù)據(jù)文件,我想在同一個圖上繪制所有數(shù)據(jù),但顏色不同.我使用以下代碼
from pylab import loadtxt, average, std, argsort
from os import listdir
from fnmatch import fnmatch
import matplotlib.pyplot as plt
a=[]
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],m_abs[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],m_phy[T_sort],yerr=m_phy_err[T_sort],fmt='r^')
plt.show()
可能我可以使用整數(shù)并使用整數(shù)來指定繪圖的顏色.有人可以幫我解釋語法嗎?
如果文件/圖的數(shù)量很小,你可以制作一個顏色數(shù)組,其長度與上面的數(shù)組相同:類似于:
colors = ["red", "blue" , "green", "orange", "purple"]
ncolor = 0
for file in a:
plt.semilogx(T[T_sort], m_abs[T_sort], 'o-', color=colors[ncolor])
ncolor+=1
總結
以上是生活随笔為你收集整理的python循环变颜色_在Python中使用循环变量在matplotlib中指定颜色的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python图像识别车票_是程序员就用P
- 下一篇: python快速加引号_在python中