我试图从这两组数据中进行绘图。这是有效的,除了颜色。我试图匹配ufiles和dfiles的颜色,以便来自ufile [1]和dfiles [1]的行将具有相同的颜色。
我怎么能得到它?
#!/usr/bin/env python3
# import np
import pylab
ufiles = ["dos_u_Co.dat", "dos_u_Fe.dat", "dos_u_Re.dat", "dos_u_tot.dat"]
dfiles = ["dos_d_Co.dat", "dos_d_Fe.dat", "dos_d_Re.dat", "dos_d_tot.dat"]
colors = ('b', 'g', 'r','c')
datalist = [ ( pylab.loadtxt(filename)) for filename in ufiles ]
for data in datalist:
pylab.plot( data[:,0], data[:,1], label=datalist)
datalist = [ ( pylab.loadtxt(filename)) for filename in dfiles ]
for data in datalist:
pylab.plot( data[:,0], -1*data[:,1], label=datalist)
pylab.show()
答案 0 :(得分:1)
在使用zip
循环colors
时循环浏览datalist
,然后使用color
kwarg设置绘图颜色:
import pylab
ufiles = ["dos_u_Co.dat", "dos_u_Fe.dat", "dos_u_Re.dat", "dos_u_tot.dat"]
dfiles = ["dos_d_Co.dat", "dos_d_Fe.dat", "dos_d_Re.dat", "dos_d_tot.dat"]
colors = ('b', 'g', 'r','c')
datalist = [ ( pylab.loadtxt(filename)) for filename in ufiles ]
for data, color in zip(datalist, colors):
pylab.plot( data[:,0], data[:,1], color=color, label=datalist)
datalist = [ ( pylab.loadtxt(filename)) for filename in dfiles ]
for data, color in zip(datalist, colors):
pylab.plot( data[:,0], -1*data[:,1], color=color, label=datalist)
pylab.show()