def calculate(): rootdir = askdirectory() path.set(rootdir) for parent, dirnames, filenames in os.walk( rootdir): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 for filename in filenames: #输出文件信息 nroot1 = os.path.join(parent, filename) nroot = nroot1.replace('/', '\\') if '.xls' in nroot and '汇总' not in nroot: data = xlrd.open_workbook(nroot) sheet1 = data.sheet_by_index(0) if sheet1.nrows > 300: EtaMax = 0 for j in range(1, 301): if float(sheet1.cell(j, 3).value) > EtaMax: EtaMax = float(sheet1.cell(j, 3).value) GPMax = float(sheet1.cell(j, 1).value) a = 0 for i1 in range(2, 301): if float(sheet1.cell(i1, 1).value) > 10 and a == 0: GP10 = float(sheet1.cell(i1, 3).value) - ( float(sheet1.cell(i1, 3).value) - float(sheet1.cell(i1 - 1, 3).value)) / ( float(sheet1.cell(i1, 1).value) - float(sheet1.cell(i1 - 1, 1).value)) * ( float(sheet1.cell(i1, 1).value) - 10) a += 1 b = 0 for i2 in range(2, 301): if float(sheet1.cell(i2, 1).value) > 5 and b == 0: GP5 = float(sheet1.cell(i2, 3).value) - ( float(sheet1.cell(i2, 3).value) - float(sheet1.cell(i2 - 1, 3).value)) / ( float(sheet1.cell(i2, 1).value) - float(sheet1.cell(i2 - 1, 1).value)) * ( float(sheet1.cell(i2, 1).value) - 5) b += 1 Eta100 = float(sheet1.cell(100, 3).value) Eta200 = float(sheet1.cell(200, 3).value) Eta300 = float(sheet1.cell(300, 3).value) bkcopy = copy(data) shcopy = bkcopy.get_sheet(0) if EtaMax: shcopy.write(1, 8, EtaMax) if GPMax: shcopy.write(1, 9, GPMax) if GP5: shcopy.write(1, 10, GP5) if GP10: shcopy.write(1, 11, GP10) if Eta100: shcopy.write(1, 12, Eta100) if Eta200: shcopy.write(1, 13, Eta200) if Eta300: shcopy.write(1, 14, Eta300) bkcopy.save(nroot) #保存
def get_fixture_icon(self, fixture): """Return an SVG group for a single fixture. Search the package data for a symbol for this fixture, then transform as appropriate based on tags and plot scaling. Args: fixture: the fixture object to create an icon for. Returns: An ElementTree object representing an SVG 'g' element. """ # Get the base SVG element symbol_name = fixture.data['symbol'] tree = ET.parse(get_data('symbol/'+symbol_name+'.svg')) root = tree.getroot() svg_ns = {'ns0': 'http://www.w3.org/2000/svg'} symbol = root.find('ns0:g', svg_ns) # Transform based on scaling and data centre = self.get_page_dimensions()[0]/2 plaster = self.get_plaster_coord() scale = float(self.options['scale']) plot_pos = lambda dim: (float(fixture.data['pos'+dim])*1000) rotation = fixture.get_rotation() colour = fixture.get_colour() symbol.set('transform', 'scale( '+str(1/scale)+' ) ' 'translate('+str(centre*scale+plot_pos('X'))+' '+ str(plot_pos('Y')+plaster*scale)+') ' 'rotate('+str(rotation)+')') for path in symbol: if path.get('class') == 'outer': path.set('fill', colour) path.set('stroke-width', str(float(self.options['line-weight-heavy'])*scale)) return symbol
def get_background_image(self): """Get the background image from file. Returns: The first group element of the SVG image file. """ scale = float(self.options['scale']) svg_ns = {'ns0': 'http://www.w3.org/2000/svg'} xloc = self.get_page_dimensions()[0]/2 yloc = self.get_plaster_coord() image_file = os.path.expanduser(self.options['background-image']) image_tree = ET.parse(image_file) image_root = image_tree.getroot() image_group = image_root.find('ns0:g', svg_ns) image_group.set('transform', 'scale('+str(1/scale)+') ' 'translate('+str(xloc*scale)+' '+ str(yloc*scale)+')') for path in image_group: path_class = path.get('class') if path.get('class') in reference.usitt_line_weights: weight = reference.usitt_line_weights[path_class] else: weight = 'line-weight-medium' path.set('stroke-width', str(float(self.options[weight])*scale)) return image_group
def collectall(): rootdir = askdirectory() path.set(rootdir) file_path = 'D:\\' + '原始流变汇总.xls' bk1 = xlrd.open_workbook('D:/原始流变汇总.xls') sh1 = bk1.sheet_by_index(0) k = sh1.nrows #获取表格中已有行数 bkcopy1 = copy(bk1) shcopy1 = bkcopy1.get_sheet(0) for parent, dirnames, filenames in os.walk( rootdir): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 for filename in filenames: #输出文件信息 nroot1 = os.path.join(parent, filename) nroot = nroot1.replace('/', '\\') test = nroot.replace('.xls', '') test1 = test[len(rootdir) + 1:] if '.xls' in nroot and '汇总' not in nroot: data = xlrd.open_workbook(nroot) sheet1 = data.sheet_by_index(0) rownum = sheet1.nrows colnum = sheet1.ncols try: for i in range(1, 301): for j in range(7): if sheet1.cell(i, j).value: shcopy1.write(k, j + 1, sheet1.cell(i, j).value) shcopy1.write(k, 0, test1) k += 1 #保存 except: print(nroot) bkcopy1.save(file_path)
def selectPath(): rootdir = askdirectory() path.set(rootdir) for parent, dirnames, filenames in os.walk( rootdir): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 #print(filenames) #for filename in filenames: # list=os.path.join(parent,filename) for file in filenames: #print(filenames) if len(file) == 32: file_or = open(parent + slash + file, 'rb') file_de = open('D:/gif/' + file + '.gif', 'wb') first_200bytes = file_or.read(200) index = 0 for byte_value in first_200bytes: if index == 1: if byte_value % 16 % 2 == 0: file_de.write(struct.pack('B', byte_value + 1)) pass else: file_de.write(struct.pack('B', byte_value - 1)) pass else: file_de.write(struct.pack('B', byte_value)) pass index = (0 if index == 1 else 1) pass # file_de.write(b'GIF89a\xc8\x01'); file_de.write(file_or.read()) pass
def changetoxls(): rootdir = askdirectory() path.set(rootdir) for parent, dirnames, filenames in os.walk( rootdir): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 for filename in filenames: #输出文件信息 nroot = os.path.join(parent, filename) if '.xml' in nroot: fullpath = nroot.replace('\\', '/') #得到文件完整路径 fullpathxls = nroot.replace('.xml', '.xls') tree = ET.parse(fullpath) root1 = tree.getroot() n = 0 file = xlwt.Workbook() #创建一个工作簿 table = file.add_sheet('sheet 1') #创建一个工作表 table.write(0, 1, 'GP in 1/s') table.write(0, 2, 'Tau in Pa') table.write(0, 3, 'Eta in mPas') table.write(0, 4, 'T in oC') table.write(0, 5, 't in s') table.write(0, 6, 't_seg in s') #写入表头 if 'mPas' in root1[3][0][0][3][0].text: changeunit = 1 else: changeunit = 1000 for data in root1.iter(root1[3][0][0][0][0].tag): if n > 6 and (n % 7) == 3: table.write(n // 7, n % 7, float(data.text) * changeunit) #写入 elif n > 6 and (n % 7) != 0 and (n % 7) != 3: table.write(n // 7, n % 7, float(data.text)) #写入 elif n > 6: table.write(n // 7, n % 7, data.text) n += 1 file.save(fullpathxls) #保存
def _write_svg(cls, qrpath, sample_id, patient_id, patient_abbrev, lines, show_borders, response): svg = cls._load_sample_svg() root = svg.getroot() path = root.find(".//svg:path[@id='qr-path']", namespaces=cls.nsmap) if path is not None: path.set("d", qrpath) sid = root.find(".//svg:text[@id='sample_id']", namespaces=cls.nsmap) if sid is not None: sid.text = sample_id sid = root.find(".//svg:text[@id='patient_id']", namespaces=cls.nsmap) if sid is not None: sid.text = patient_id sid = root.find(".//svg:text[@id='patient_abbrev']", namespaces=cls.nsmap) if sid is not None: sid.text = patient_abbrev for i in range(6): st = root.find(".//svg:tspan[@id='sample_type_line%d']" % (i + 1), namespaces=cls.nsmap) if st is not None: st.text = lines[i] if i < len(lines) else "" if not show_borders: g = root.find(".//svg:g[@id='stickers']", namespaces=cls.nsmap) if g is not None: root.remove(g) svg.write(response, encoding="utf-8", xml_declaration=True) return response
def selectPath(): rootdir = askdirectory() path.set(rootdir) for parent, dirnames, filenames in os.walk(rootdir): for filename in filenames: #输出文件信息 list = os.path.join(parent, filename) #print(list) if '.csv' in list and '-d' not in list and '-D' not in list and '-0' not in list and '_dark' not in list and '_d' not in list: #bk = xlrd.open_workbook('D:/python/1.xlsx') #sh = bk.sheet_by_index(0) c = open(list, "r") #以r的方式打开csv文件 read = csv.reader(c) test = list.replace('csv', 'xls') test1 = test[len(rootdir):] test2 = test1.replace('\\', ' ') #lst2.append(test) #print (lst) file_path = 'D:\\solarcell\\' + test2 file = xlwt.Workbook() #创建一个工作簿 table = file.add_sheet('sheet 1') #创建一个工作表 n = 0 for line in read: if n > 46 and len(line) > 3: a = line[2] b = line[3] table.write(n - 47, 0, a) #写入 table.write(n - 47, 1, b) n += 1 file.save(file_path) #保存
def selectPath(): global path_ path_ = askdirectory() path.set(path_) print(path_) return path_
def changetoxml(): rootdir = askdirectory() path.set(rootdir) for parent, dirnames, filenames in os.walk( rootdir): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 for filename in filenames: #输出文件信息 nroot = os.path.join(parent, filename) if '.txt' in nroot: fullpath = nroot.replace('\\', '/') #得到文件完整路径 newname = fullpath.replace('.txt', '.xml') os.rename(fullpath, newname)
def get_fixture_group(self): """Return a transformed symbol g element.""" posX_mm = float(self.fixture.data['posX'])*1000 posY_mm = float(self.fixture.data['posY'])*1000 rotation_deg = self.fixture.data['rotation'] colour = self.fixture.data['colour'] self.image_group.set('transform', 'translate('+ str(posX_mm)+' '+str(posY_mm)+') rotate('+str(rotation_deg)+')') for path in self.image_group: if path.get('class') == 'outer': path.set('fill', colour) return self.image_group
def select_path(): #default_dir = os.path.join(os.path.expanduser('~'), 'Desktop', 'docbook-to-epub') default_dir = os.path.join(os.path.expanduser('~'), 'Downloads', 'Main') main_xml = askopenfilename(initialdir=default_dir, title='Choose Main.xml', filetypes=(('Xml files', '*.xml'), ('All files', '*.*'))) path.set(main_xml) global choose_file_name choose_file_name = os.path.basename(main_xml) empty_log() write_to_log('[Choose Dir:] ' + os.path.split(main_xml)[0]) convert(remove_biblioentry(main_xml))
def changetotxt(): rootdir = askdirectory() path.set(rootdir) for parent, dirnames, filenames in os.walk( rootdir): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 for filename in filenames: #输出文件信息 nroot = os.path.join(parent, filename) if '.xml' in nroot: fullpath = nroot.replace('\\', '/') #得到文件完整路径 #manager = Manager() #manager.add_new_doc(fullpath) newname = fullpath.replace('.xml', '.txt') os.rename(fullpath, newname) return rootdir
def changetoutf8(): rootdir = askdirectory() path.set(rootdir) for parent, dirnames, filenames in os.walk( rootdir): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 for filename in filenames: #输出文件信息 nroot = os.path.join(parent, filename) if '.txt' in nroot: fullpath = nroot.replace('\\', '/') #得到文件完整路径 f = open(fullpath, "r", encoding='utf-8', errors='ignore') con = f.read() newpath = fullpath.replace('.txt', '-new.txt') open(fullpath, 'w+', encoding='utf-8').write( re.sub(r'xml version="1.0"', r'xml version="1.0" encoding="UTF-8"', con))
def choosepic(): '''上傳圖片,並顯示路徑和縮圖在視窗中''' path_ = askopenfilename() path.set(path_) # 顯示位置(path) e1 = Entry(root, state='readonly', text=path) e1.grid(row=3, columnspan=2) # 顯示縮圖 im = Image.open(e1.get()) im = im.resize((160, 160)) img = ImageTk.PhotoImage(im) l1 = Label(root, height=160) l1.grid(row=4, columnspan=2) l1.config(image=img) l1.image = img #keep a reference
def addall(): rootdir = askdirectory() path.set(rootdir) file_path = 'D:\\' + '流变汇总.xls' bk1 = xlrd.open_workbook('D:/流变汇总.xls') #获取表格中已有行数 sh1 = bk1.sheet_by_index(0) k = sh1.nrows bkcopy1 = copy(bk1) shcopy1 = bkcopy1.get_sheet(0) for parent, dirnames, filenames in os.walk( rootdir): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 for filename in filenames: #输出文件信息 nroot1 = os.path.join(parent, filename) nroot = nroot1.replace('/', '\\') test = nroot.replace('.xls', '') test1 = test[len(rootdir) + 1:] if '.xls' in nroot and '汇总' not in nroot: data = xlrd.open_workbook(nroot) sheet1 = data.sheet_by_index(0) shcopy1.write(k, 0, test1) try: if sheet1.cell(1, 8).value: shcopy1.write(k, 1, sheet1.cell(1, 8).value) if sheet1.cell(1, 9).value: shcopy1.write(k, 2, sheet1.cell(1, 9).value) if sheet1.cell(1, 10).value: shcopy1.write(k, 3, sheet1.cell(1, 10).value) if sheet1.cell(1, 11).value: shcopy1.write(k, 4, sheet1.cell(1, 11).value) if sheet1.cell(1, 12).value: shcopy1.write(k, 5, sheet1.cell(1, 12).value) if sheet1.cell(1, 13).value: shcopy1.write(k, 6, sheet1.cell(1, 13).value) if sheet1.cell(1, 14).value: shcopy1.write(k, 7, sheet1.cell(1, 14).value) bkcopy1.save(file_path) k += 1 #保存 except: print(nroot)
def collectall(): rootdir = askdirectory() path.set(rootdir) file_path = rootdir.replace('\\', '/') + '/原始流变汇总.xls' if not os.path.exists(file_path): file = xlwt.Workbook() #创建一个工作簿 table = file.add_sheet('sheet 1') #创建一个工作表 file.save(file_path) print('汇总文件' + file_path + '创建成功!') else: print('汇总文件已存在') bk1 = xlrd.open_workbook(file_path) sh1 = bk1.sheet_by_index(0) k = sh1.nrows #获取表格中已有行数 bkcopy1 = copy(bk1) shcopy1 = bkcopy1.get_sheet(0) for parent, dirnames, filenames in os.walk( rootdir): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 for filename in filenames: #输出文件信息 nroot1 = os.path.join(parent, filename) nroot = nroot1.replace('/', '\\') test = nroot.replace('.xls', '') test1 = test[len(rootdir) + 1:] if '.xls' in nroot and '汇总' not in nroot: data = xlrd.open_workbook(nroot) sheet1 = data.sheet_by_index(0) rownum = sheet1.nrows colnum = sheet1.ncols try: for i in range(1, 301): for j in range(7): if sheet1.cell(i, j).value: shcopy1.write(k, j + 1, sheet1.cell(i, j).value) shcopy1.write(k, 0, test1) k += 1 #保存 except: print(nroot) bkcopy1.save(file_path)
def selectPath(): rootdir = askdirectory() path.set(rootdir) for parent, dirnames, filenames in os.walk( rootdir): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 for filename in filenames: #输出文件信息 list = os.path.join(parent, filename) if '.csv' in list and '-d' not in list and '-D' not in list and '-0' not in list and '_dark' not in list and '_d' not in list: c = open(list, "r") #以r的方式打开csv文件 read = csv.reader(c) test = list.replace('csv', 'xls') test1 = test[len(rootdir):] test2 = test1.replace('.xls', '') file_path = 'D:\\solarcell\\' + '汇总.xls' #file = xlwt.Workbook() #创建一个工作簿 #table = file.add_sheet('sheet 1') #创建一个工作表 style = xlwt.easyxf(num_format_str='#,##0.00') bk = xlrd.open_workbook('D:/solarcell/汇总.xls') #获取表格中已有行数 sh = bk.sheet_by_index(0) n = 0 i = sh.nrows bkcopy = copy(bk) shcopy = bkcopy.get_sheet(0) try: for line in read: if n == 1 and len(line) > 10: shcopy.write(i, 0, test2, style) for j in range(6, 12): a = line[j] shcopy.write(i, j - 5, a, style) elif n == 1 and len(line) < 10: shcopy.write(i, 0, test2, style) n += 1 bkcopy.save(file_path) #保存''' except: print(test2)
def GetPath(): """选择源图像 """ path.set(filedialog.askopenfilename())
if (child.tag == 'phonons'): child.set('do', 'skip') for subchild in child: child.remove(subchild) phonondos = ET.SubElement(child, 'phonondos') phonondos.set('ngrdos', '100') phonondos.set('nwdos', '500') phonondos.set('ntemp', '200') phonondos.set('nsmdos', '2') phonondispplot = ET.SubElement(child, 'phonondispplot') plot1d = ET.SubElement(phonondispplot, 'plot1d') path = ET.SubElement(plot1d, 'path') path.set('steps', '200') point = ET.SubElement(path, 'point') point.set('coord', '1.0 0.0 0.0') point = ET.SubElement(path, 'point') point.set('coord', '0.5 0.5 0.0') point = ET.SubElement(path, 'point') point.set('coord', '0.0 0.0 0.0') point = ET.SubElement(path, 'point') point.set('coord', '0.5 0.0 0.0') indent(root) tree.write('input.xml') os.system('touch phrun') os.chdir('../')
def calculate(): rootdir = askdirectory() path.set(rootdir) for parent, dirnames, filenames in os.walk( rootdir): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 for filename in filenames: #输出文件信息 list1 = os.path.join(parent, filename) list = list1.replace('/', '\\') if '.xls' in list and '汇总' not in list: data = xlrd.open_workbook(list) sheet1 = data.sheet_by_index(0) a = 0 if sheet1.nrows == 600: for i1 in range(600): if float(sheet1.cell(i1, 0).value) > 0 and a == 0: Isc1 = float(sheet1.cell(i1, 1).value) - ( float(sheet1.cell(i1, 1).value) - float(sheet1.cell(i1 - 1, 1).value) ) / (float(sheet1.cell(i1, 0).value) - float(sheet1.cell(i1 - 1, 0).value)) * float( sheet1.cell(i1, 0).value) Isc = Isc1 / 20.28 * 1000 * (-1) bkcopy = copy(data) shcopy = bkcopy.get_sheet(0) shcopy.write(1, 6, Isc) bkcopy.save(list) #保存 a += 1 #print(Isc) # for parent,dirnames,filenames in os.walk(rootdir): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 # for filename in filenames: #输出文件信息 # list1=os.path.join(parent,filename) # list=list1.replace('/','\\') # if '.xls' in list and '汇总' not in list: # data=xlrd.open_workbook(list) # sheet1=data.sheet_by_index(0) b = 0 for i2 in range(600): if float(sheet1.cell(i2, 1).value) > 0 and b == 0: Voc = float(sheet1.cell(i2, 0).value) - ( float(sheet1.cell(i2, 0).value) - float(sheet1.cell(i2 - 1, 0).value) ) / (float(sheet1.cell(i2, 1).value) - float(sheet1.cell(i2 - 1, 1).value)) * float( sheet1.cell(i2, 1).value) bkcopy = copy(data) shcopy = bkcopy.get_sheet(0) shcopy.write(1, 7, Voc) bkcopy.save(list) #保存 b += 1 #print(Voc) #for parent,dirnames,filenames in os.walk(rootdir): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 #for filename in filenames: #输出文件信息 #list1=os.path.join(parent,filename) #list=list1.replace('/','\\') #if '.xls' in list and '汇总' not in list: #data=xlrd.open_workbook(list) #sheet1=data.sheet_by_index(0) pmax = 0 for j in range(600): if float(sheet1.cell(j, 0).value) * float( sheet1.cell(j, 1).value) * (-1) > pmax: pmax = float(sheet1.cell(j, 0).value) * float( sheet1.cell(j, 1).value) * (-1) eff = pmax / 20.28 * 1000 #print(Isc,Voc) Pmax = Isc * Voc FF = eff / Pmax #style = xlwt.easyxf(num_format_str='#,##0.0000') bkcopy = copy(data) shcopy = bkcopy.get_sheet(0) shcopy.write(1, 8, FF) shcopy.write(1, 9, eff) bkcopy.save(list) #保存 for filename in filenames: #输出文件信息 list1 = os.path.join(parent, filename) list = list1.replace('/', '\\') if '.xls' in list and '汇总' not in list: data = xlrd.open_workbook(list) sheet1 = data.sheet_by_index(0) a = 0 if sheet1.nrows == 600: for i1 in range(600): if float(sheet1.cell(i1, 0).value) > 0 and a == 0: Isc1 = float(sheet1.cell(i1, 1).value) - ( float(sheet1.cell(i1, 1).value) - float(sheet1.cell(i1 - 1, 1).value) ) / (float(sheet1.cell(i1, 0).value) - float(sheet1.cell(i1 - 1, 0).value)) * float( sheet1.cell(i1, 0).value) Isc = Isc1 / 20.28 * 1000 * (-1) bkcopy = copy(data) shcopy = bkcopy.get_sheet(0) shcopy.write(1, 6, Isc) bkcopy.save(list) #保存 a += 1 for filename in filenames: #输出文件信息 list1 = os.path.join(parent, filename) list = list1.replace('/', '\\') if '.xls' in list and '汇总' not in list: data = xlrd.open_workbook(list) sheet1 = data.sheet_by_index(0) if sheet1.nrows == 600: b = 0 for i2 in range(600): if float(sheet1.cell(i2, 1).value) > 0 and b == 0: Voc = float(sheet1.cell(i2, 0).value) - ( float(sheet1.cell(i2, 0).value) - float(sheet1.cell(i2 - 1, 0).value) ) / (float(sheet1.cell(i2, 1).value) - float(sheet1.cell(i2 - 1, 1).value)) * float( sheet1.cell(i2, 1).value) bkcopy = copy(data) shcopy = bkcopy.get_sheet(0) shcopy.write(1, 7, Voc) bkcopy.save(list) #保存 b += 1
def selectPath(): path_ = askopenfilename() path.set(path_)
def parse_cmds_to_svg(cmds): """ Given a list of parsed Skia commands, builds an SVG Element tree. """ svg = ET.Element("svg", {"xmlns": "http://www.w3.org/2000/svg"}) # Append an initial path element. ET.SubElement(svg, "path", {"d": "", "stroke-linecap": "round"}) for name, values in cmds: if name == "CANVAS_DIMENSIONS" and len(values) == 2: set_bounding_box(svg, values[0], values[1]) elif name == "CANVAS_DIMENSIONS" and len(values) == 1: set_bounding_box(svg, values[0], values[0]) elif name == "NEW_PATH": ET.SubElement(svg, "path", {"d": "", "stroke-linecap": "round"}) # Stroke command is meant to switch from fill to stroke. elif name == "STROKE": path = svg.find("path[last()]") path.set("fill", "none") path.set("stroke", "black") path.set("stroke-width", values[0]) elif name == "CAP_SQUARE": path = svg.find("path[last()]") path.set("stroke-linecap", "square") elif name == "CLOSE": path = svg.find("path[last()]") append_d(path, "Z") elif name == "MOVE_TO": path = svg.find("path[last()]") append_d(path, "M", values[0], values[1]) elif name == "R_MOVE_TO": path = svg.find("path[last()]") append_d(path, "m", values[0], values[1]) elif name == "LINE_TO": path = svg.find("path[last()]") append_d(path, "L", values[0], values[1]) elif name == "R_LINE_TO": path = svg.find("path[last()]") append_d(path, "l", values[0], values[1]) elif name == "H_LINE_TO": path = svg.find("path[last()]") append_d(path, "H", values[0]) elif name == "R_H_LINE_TO": path = svg.find("path[last()]") append_d(path, "h", values[0]) elif name == "V_LINE_TO": path = svg.find("path[last()]") append_d(path, "V", values[0]) elif name == "R_V_LINE_TO": path = svg.find("path[last()]") append_d(path, "v", values[0]) elif name == "CUBIC_TO": path = svg.find("path[last()]") append_d(path, "C", *values) elif name == "R_CUBIC_TO": path = svg.find("path[last()]") append_d(path, "c", *values) elif name == "CUBIC_TO_SHORTHAND": path = svg.find("path[last()]") append_d(path, "S", *values) elif name == "ARC_TO": path = svg.find("path[last()]") append_d(path, "A", *values) elif name == "R_ARC_TO": path = svg.find("path[last()]") append_d(path, "a", *values) return svg
def selectPath(): path_ = filedialog.askdirectory() path.set(path_)
def documentselectinone(width=120, height=1000000): xall = [] yall = [] name = [] color = [ "black", "b", "r", "g", "purple", "olive", "chocolate", "deepskyblue", "darkorange", "lime", "grey", "royalblue" ] cnames = { 'aliceblue': '#F0F8FF', 'antiquewhite': '#FAEBD7', 'aqua': '#00FFFF', 'aquamarine': '#7FFFD4', 'azure': '#F0FFFF', 'beige': '#F5F5DC', 'bisque': '#FFE4C4', 'black': '#000000', 'blanchedalmond': '#FFEBCD', 'blue': '#0000FF', 'blueviolet': '#8A2BE2', 'brown': '#A52A2A', 'burlywood': '#DEB887', 'cadetblue': '#5F9EA0', 'chartreuse': '#7FFF00', 'chocolate': '#D2691E', 'coral': '#FF7F50', 'cornflowerblue': '#6495ED', 'cornsilk': '#FFF8DC', 'crimson': '#DC143C', 'cyan': '#00FFFF', 'darkblue': '#00008B', 'darkcyan': '#008B8B', 'darkgoldenrod': '#B8860B', 'darkgray': '#A9A9A9', 'darkgreen': '#006400', 'darkkhaki': '#BDB76B', 'darkmagenta': '#8B008B', 'darkolivegreen': '#556B2F', 'darkorange': '#FF8C00', 'darkorchid': '#9932CC', 'darkred': '#8B0000', 'darksalmon': '#E9967A', 'darkseagreen': '#8FBC8F', 'darkslateblue': '#483D8B', 'darkslategray': '#2F4F4F', 'darkturquoise': '#00CED1', 'darkviolet': '#9400D3', 'deeppink': '#FF1493', 'deepskyblue': '#00BFFF', 'dimgray': '#696969', 'dodgerblue': '#1E90FF', 'firebrick': '#B22222', 'floralwhite': '#FFFAF0', 'forestgreen': '#228B22', 'fuchsia': '#FF00FF', 'gainsboro': '#DCDCDC', 'ghostwhite': '#F8F8FF', 'gold': '#FFD700', 'goldenrod': '#DAA520', 'gray': '#808080', 'green': '#008000', 'greenyellow': '#ADFF2F', 'honeydew': '#F0FFF0', 'hotpink': '#FF69B4', 'indianred': '#CD5C5C', 'indigo': '#4B0082', 'ivory': '#FFFFF0', 'khaki': '#F0E68C', 'lavender': '#E6E6FA', 'lavenderblush': '#FFF0F5', 'lawngreen': '#7CFC00', 'lemonchiffon': '#FFFACD', 'lightblue': '#ADD8E6', 'lightcoral': '#F08080', 'lightcyan': '#E0FFFF', 'lightgoldenrodyellow': '#FAFAD2', 'lightgreen': '#90EE90', 'lightgray': '#D3D3D3', 'lightpink': '#FFB6C1', 'lightsalmon': '#FFA07A', 'lightseagreen': '#20B2AA', 'lightskyblue': '#87CEFA', 'lightslategray': '#778899', 'lightsteelblue': '#B0C4DE', 'lightyellow': '#FFFFE0', 'lime': '#00FF00', 'limegreen': '#32CD32', 'linen': '#FAF0E6', 'magenta': '#FF00FF', 'maroon': '#800000', 'mediumaquamarine': '#66CDAA', 'mediumblue': '#0000CD', 'mediumorchid': '#BA55D3', 'mediumpurple': '#9370DB', 'mediumseagreen': '#3CB371', 'mediumslateblue': '#7B68EE', 'mediumspringgreen': '#00FA9A', 'mediumturquoise': '#48D1CC', 'mediumvioletred': '#C71585', 'midnightblue': '#191970', 'mintcream': '#F5FFFA', 'mistyrose': '#FFE4E1', 'moccasin': '#FFE4B5', 'navajowhite': '#FFDEAD', 'navy': '#000080', 'oldlace': '#FDF5E6', 'olive': '#808000', 'olivedrab': '#6B8E23', 'orange': '#FFA500', 'orangered': '#FF4500', 'orchid': '#DA70D6', 'palegoldenrod': '#EEE8AA', 'palegreen': '#98FB98', 'paleturquoise': '#AFEEEE', 'palevioletred': '#DB7093', 'papayawhip': '#FFEFD5', 'peachpuff': '#FFDAB9', 'peru': '#CD853F', 'pink': '#FFC0CB', 'plum': '#DDA0DD', 'powderblue': '#B0E0E6', 'purple': '#800080', 'red': '#FF0000', 'rosybrown': '#BC8F8F', 'royalblue': '#4169E1', 'saddlebrown': '#8B4513', 'salmon': '#FA8072', 'sandybrown': '#FAA460', 'seagreen': '#2E8B57', 'seashell': '#FFF5EE', 'sienna': '#A0522D', 'silver': '#C0C0C0', 'skyblue': '#87CEEB', 'slateblue': '#6A5ACD', 'slategray': '#708090', 'snow': '#FFFAFA', 'springgreen': '#00FF7F', 'steelblue': '#4682B4', 'tan': '#D2B48C', 'teal': '#008080', 'thistle': '#D8BFD8', 'tomato': '#FF6347', 'turquoise': '#40E0D0', 'violet': '#EE82EE', 'wheat': '#F5DEB3', 'white': '#FFFFFF', 'whitesmoke': '#F5F5F5', 'yellow': '#FFFF00', 'yellowgreen': '#9ACD32' } morecolor = [] for key in cnames: morecolor.append(cnames[key]) #print(morecolor) rootdir = askdirectory() path.set(rootdir) for parent, dirnames, filenames in os.walk( rootdir): #三个参数:分别返回1.父目录 2.所有文件夹名字(不含路径) 3.所有文件名字 for filename in filenames: list1 = os.path.join(parent, filename) nowdir = list1.replace('\\', '/') npath = rootdir.replace('\\', '/') npath1 = npath + '/AllInOne.png' if '.xls' in nowdir and '汇总' not in nowdir: labelname = filename.replace(".xls", '') name.append(labelname) data = xlrd.open_workbook(nowdir) sheet1 = data.sheet_by_index(0) x = [] y = [] for i in range(1, 301): if float(sheet1.cell(i, 1).value) > 0 and float( sheet1.cell(i, 3).value) > 0: x.append(float(sheet1.cell(i, 1).value)) y.append(float(sheet1.cell(i, 3).value)) xall.append(x) yall.append(y) # 删除xls文档 #os.remove(nfile_path) #print("xls文件删除成功!") # 通过rcParams设置全局横纵轴字体大小 matplotlib.pyplot.rcParams['font.sans-serif'] = ['Arial'] matplotlib.rcParams['xtick.direction'] = 'in' matplotlib.rcParams['ytick.direction'] = 'in' matplotlib.rcParams['xtick.labelsize'] = 12 matplotlib.rcParams['ytick.labelsize'] = 12 font = { 'family': 'Arial', 'color': 'black', 'weight': 'normal', 'size': 16, } matplotlib.pyplot.figure('IV Curve', figsize=(6, 4.5)) ax = matplotlib.pyplot.subplot(1, 1, 1) ax.spines['bottom'].set_linewidth(1.3) ax.spines['left'].set_linewidth(1.3) ax.spines['top'].set_linewidth(1.3) ax.spines['right'].set_linewidth(1.3) # 通过'k'指定线的颜色,lw指定线的宽度 # 第三个参数除了颜色也可以指定线形,比如'r--'表示红色虚线 # 更多属性可以参考官网:http://matplotlib.org/api/pyplot_api.html if len(name) < 13: lenth = len(name) for i in range(lenth): matplotlib.pyplot.plot(xall[i], yall[i], color[i], lw=2, label=name[i]) else: lenth = len(name) for i in range(lenth): matplotlib.pyplot.plot(xall[i], yall[i], morecolor[i], lw=2, label=name[i]) matplotlib.pyplot.xlim(0, width) matplotlib.pyplot.xlabel('GP (1/s)', fontdict=font) matplotlib.pyplot.ylim(0, height) matplotlib.pyplot.ylabel('Eta (Pas)', fontdict=font) # scatter可以更容易地生成散点图 #matplotlib.pyplot.scatter(x, y) matplotlib.pyplot.grid(False) matplotlib.pyplot.legend() # 将当前figure的图保存到文件 print(npath1 + "图片保存成功!") matplotlib.pyplot.savefig(npath1, bbox_inches='tight', dpi=300) matplotlib.pyplot.show()