2017-02-17 54 views
0

我想從這兩組數據中作圖。這是工作,除了顏色。我試圖匹配ufiles和dfiles的顏色,以使ufile [1]和dfiles [1]中的行具有相同的顏色。控制顏色順序,並在y = 0處畫一條線

我怎麼能得到它?通過colors

#!/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() 

回答

1

只是週期你循環使用,雖然zip,然後使用color kwarg集劇情顏色datalist

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() 
+0

親愛的湯姆:非常感謝。 – BaRud

+0

還有一件事:你能不能請添加一行來設置xlim,ylim?我試過'pylab.set_xlim =([ - 4,3]) pylab.ylim =([ - 4,3])' 但它們沒有任何影響 – BaRud

+1

從上面的行中刪除'='例如'pylab.xlim([ - 4,3])' – tom