繪圖爲每一行生成不同的顏色,但我也需要爲該圖生成不同的line_styles。搜索了一些信息後,我找到了itertools模塊。但是我無法生成錯誤圖:沒有Line2D屬性「shape_list」。我無法迭代line_styles(Matplotlib)
import itertools
from glob import glob
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
shape_list = ["square", "triangle", "circle", "pentagon", "star", "octagon"]
# loop over all files in the current directory ending with .txt
for fname in glob("*.txt"):
# read file, skip header (1 line) and unpack into 3 variables
WL, ABS, T = np.genfromtxt(fname, skip_header=1, unpack=True)
g = itertools.cycle(shape_list)
plt.plot(WL, T, label=fname[0:3],shape_list = g.__next__())
plt.xlabel('Wavelength (nm)')
plt.xlim(200,1000)
plt.ylim(0,100)
plt.ylabel('Transmittance (%)')
mpl.rcParams.update({'font.size': 12})
plt.legend(loc=4,prop={'size':10})
plt.grid(True)
#plt.legend(loc='lower center')
plt.savefig('Transmittance', dpi=600)
是的。它可以工作,但線條無法區分。看起來他們有背景和頻率高。很難區分圓形和方形。 – esilik
如果您的標記太多以至於無法區分,則可以使用'markevery ='僅在每個x點顯示一個標記。請參閱http://matplotlib.org/examples/pylab_examples/markevery_demo.html –
非常有用的評論。謝謝! – esilik