1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
| """ Created on Sun Dec 2 20:01:32 2018 @author: spacexi """
import numpy as np import matplotlib.pyplot as plt import xlrd
def autocolor(num): color=['navy','darkgreen','red','darkmagenta','chocolate','teal','darkslateblue'] if num>6: num=num%7 return color[num] def automarker(num): marker=['o','v','s','*','^','+','3'] if num>6: num=num%7 return marker[num]
data=xlrd.open_workbook("data.xlsx") sheet0=data.sheets()[0] active_line=0 linenumber=0 line=[] legendtext=[]
plt.rcParams['figure.figsize']=(6,6) plt.rcParams['xtick.direction']='in' plt.rcParams['ytick.direction']='in' plt.rcParams['savefig.dpi'] = 300
xmin=0 xmax=8 xstep=1 ymin=0 ymax=90 ystep=10
while active_line<sheet0.ncols: if sheet0.col_values(active_line)[0]=='x': xdata=sheet0.col_values(active_line) del xdata[0] del xdata[0] xdata=list(filter(None, xdata)) elif sheet0.col_values(active_line)[0]=='y': ydata=sheet0.col_values(active_line) if sheet0.col_values(active_line)[1]!='': newlegendtext=sheet0.col_values(active_line)[1] legendtext.append(newlegendtext) del ydata[0] del ydata[0] ydata=list(filter(None, ydata)) newline,=plt.plot(xdata,ydata,linestyle="--",color=autocolor(linenumber),marker=automarker(linenumber)) line.append(newline) if (active_line+1<sheet0.ncols): if sheet0.col_values(active_line+1)[0]=='Ey': Eydata=sheet0.col_values(active_line+1) del Eydata[0] del Eydata[0] Eydata=list(filter(None, Eydata)) plt.errorbar(xdata,ydata,yerr=Eydata,fmt='none',color=autocolor(linenumber),marker=automarker(linenumber),elinewidth=1,capsize=4) linenumber+=1 active_line+=1
plt.xlim(xmin,xmax) plt.ylim(ymin,ymax) plt.xlabel('x value',fontsize=16) plt.ylabel('y value',fontsize=16) plt.axis([xmin,xmax,ymin,ymax]) plt.xticks(list(range(xmin,xmax,xstep)),fontsize=14) plt.yticks(list(range(ymin,ymax,ystep)),fontsize=14) plt.legend(line,legendtext,loc = 'upper left',fontsize=14,edgecolor='black')
plt.savefig("figure.png") plt.show()
|