''' This sample generate an image from a graph from a sample project. Please note that a file named my_py_test.png will be replaced by running this sample. ''' import originpro as op #from Learning Center folder op.open(op.path('c')+ r'\Graphing\Trellis Plots - Box Charts.opju') gg=op.find_graph(0) # export graph to an image f='' if gg: f=gg.save_fig(op.path()+'my_py_test.png',width=500) import os if len(f): os.startfile(f)
''' This sample picks all colors from an image. The RGB values for each color is output to a worksheet. This example requires Python package extcolors to be preinstalled. ''' import extcolors import numpy as np import originpro as op # choose an image to extract colors file_path = op.file_dialog('*.png;*.jpg;*.bmp','Select an Image') if len(file_path) ==0: raise ValueError('user cancel') colors, pixel_count = extcolors.extract_from_path(file_path) colors = np.array(colors) # rgb = colors[:,0] rgb,pixel = map(list, zip(*colors)) # print(rgb) r = [] g = [] b = [] for row in rgb: r.append(row[0]) g.append(row[1]) b.append(row[2]) # output colors wks = op.new_sheet() wks.from_list(0, r) wks.from_list(1, g) wks.from_list(2, b)
''' This sample shows the management of folders under Project Explorer. It sets up same folder structure as the /Sample/Python/ and create a workbook under each sub folder. ''' import os import originpro as op # Get the path string of a folder path = os.path.join(op.path('e'), 'Samples', 'Python') # Start a new project and go to the root folder in Project Explorer op.new() op.pe.cd('/UNTITLED') # Loop over subfolders under /Samples/Python/ and create subfolders with same name. for f in os.listdir(path): fd = f'{os.path.splitext(f)[0]}' op.pe.mkdir(fd) op.pe.cd(f'"{fd}"') op.new_sheet('w',fd) op.pe.cd('/UNTITLED')