├── .gitignore ├── 1. Origin-Python Data Exchange ├── DataFrame and Column Format.py ├── Get Tree in Origin as dict.py ├── Matrix Data Exchange.py ├── Putting Data to Columns.py ├── Readme.md └── Worksheet User Tree Access.py ├── 2. Worksheet ├── Import CSV with Auto Settings.py ├── Import CSV with Selected Rows.py ├── Import Excel Sheet.py ├── Import HTML Table from the Web.py ├── Import MATLAB.py ├── Import Multiple Files using Pandas into One Worksheet.py ├── Import Two Excel Sheets.py ├── Import Using a Filter.py ├── Import by Setting File Header Info.py ├── Manipulate Columns and Make Group Plot.py ├── Readme.md └── Split Dataset to Training and Testing Data.py ├── 3. Matrix ├── 3D Parametric Plot From Matrix.py ├── Download GeoTIFF Image to Make Surface Plot.py ├── Import NetCDF with Partial Settings.py ├── Matrix Dot Product using numpy.py ├── Plot Heatmap from Matrix.py ├── Use OpenCV to Load TIFF Images into Matrix Sheet.py └── readme.md ├── 4. Graphing ├── Control Plots As Group.py ├── Custom Linked Axis.py ├── Customize Legend.py ├── Customizing Graph.py ├── Graph Legend to Show Only First Plot.py ├── Line Plot with Log Scale.py ├── Merge Graphs.py ├── Multiple Layer Plot.py ├── Plot Contour and 3D Surface Graph.py ├── Plot From Data Range.py ├── Plot Heatmap from Matrix Data.py ├── Plot Symbols Indexed by Column Values.py ├── Plotting 2D Contour Plot via Virtual Matrix.py ├── Readme.md └── Stacked Column Plot.py ├── 5. Analysis ├── Batch Fitting Multiple Data Files.py ├── Extract Values from NLFit Report Tables.py ├── Fit 2 Indepedents and 2 Dependents.py ├── Linear Regression and Plot.py ├── Load and Run Multiple Linear Fit Templates.py ├── Open Dialog for Interactive Control of the Fitting.py ├── Sequential Fit Multiple Files.py ├── Simple Curve Fit on a Graph.py ├── Simple Curve Fit to XY Data.py ├── Simple Curve Fit with Report.py ├── Tabulate Multiple Nonlinear Fit Results.py └── readme.md ├── 6. Images ├── Accessing Individual Image in an Image Stack.py ├── Image Split and Merge Channels.py ├── Image Window Basics.py ├── Image thinning with opencv.py ├── Inverting an Image with skimage.py └── Load Digits Dataset from scikit-learn.py ├── 7. Miscellaneous ├── Close All Graphs at once.py ├── Export Graphs as Images from Sample Projects.py ├── Extract Image Colors.py ├── Loop through worksheets.py ├── Manage Project Explorer.py ├── Multi Threading.py └── readme.md ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | /.vs 131 | -------------------------------------------------------------------------------- /1. Origin-Python Data Exchange/DataFrame and Column Format.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to set Column Format with DataFrame and from_df, to_df functions. 3 | Make sure you've installed pandas. To install the module, 4 | open the Script Window (Shift+Alt+3), type the following and press Enter: 5 | pip install pandas 6 | 7 | The following will check and install: 8 | pip -chk pandas 9 | ''' 10 | import originpro as op 11 | import pandas as pd 12 | 13 | # Create a dataframe to fill the sheet 14 | df = pd.DataFrame({ 15 | 'Date': ['10/25/2018','02/21/2019','04/01/2020'], 16 | 'Gender':['Male','Male','Female'], 17 | 'Score': [75.5, 86.7, 91], 18 | }) 19 | 20 | df['Date'] = pd.to_datetime(df['Date']) 21 | df['Gender']= pd.Categorical(df['Gender']) 22 | 23 | wks=op.new_sheet() 24 | wks.from_df(df) 25 | 26 | #can also create book and get first sheet like this 27 | wks2=op.new_book('w', 'Copy using DF')[0] 28 | 29 | #column formats like date is automatically handled 30 | df1=wks.to_df() 31 | wks2.from_df(df1) -------------------------------------------------------------------------------- /1. Origin-Python Data Exchange/Get Tree in Origin as dict.py: -------------------------------------------------------------------------------- 1 | ''' 2 | To show how to get a Tree in Origin. 3 | Tree variables are used extensively inside Origin. In this example, we use an X-Function 4 | which will generate a Tree after its execution. The Tree will have the same name as the 5 | X-Function, which in the sample below is "fitlr". It does a simple linear fit and generates 6 | basic stats fromt the fit, see 7 | https://www.originlab.com/doc/X-Function/ref/fitLR 8 | ''' 9 | import originpro as op 10 | fn=op.path('e') + 'Samples\Curve Fitting\Linear Fit.dat' 11 | wks = op.new_sheet() 12 | wks.from_file(fn,False) 13 | #fit A(x) D(y) 14 | wks.get_book().lt_exec('fitlr (A,D)') 15 | dd = op.lt_tree_to_dict('fitlr') 16 | slope = dd['b'] 17 | err = dd['berr'] 18 | print(f'slope= {slope:.3f} +- {err:.3f}') 19 | -------------------------------------------------------------------------------- /1. Origin-Python Data Exchange/Matrix Data Exchange.py: -------------------------------------------------------------------------------- 1 | '''This example transfers a 3D Numpy array (four 3X3 matrices) into Origin, 2 | the data is saved into a matrix sheet containing four matrix objects. Then 3 | the data is extracted from the matrix sheet and saved into Numpy arrays. ''' 4 | import numpy as np 5 | import originpro as op 6 | 7 | arr=np.random.rand(4,3,3) 8 | 9 | mxs=op.new_sheet('m') 10 | mxs.from_np(arr) 11 | mxs.show_thumbnails() 12 | 13 | # Extract the data from the four matrix objects and save into a Numpy 3D array. 14 | arr_3d=mxs.to_np3d() 15 | print(arr_3d.shape) 16 | 17 | # Extract the data from the first matrix object and save into a Numpy 2D array. 18 | arr_2d=mxs.to_np2d(0) 19 | print(arr_2d.shape) -------------------------------------------------------------------------------- /1. Origin-Python Data Exchange/Putting Data to Columns.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to use from_list function to put data to Columns 3 | ''' 4 | import originpro as op 5 | 6 | # Prepare data. 7 | data=[x/10. for x in range(50)] 8 | 9 | # Prepare worksheet. 10 | wks=op.new_sheet() 11 | 12 | # Put data to col(A), and set Long Name, Units, designation as well 13 | wks.from_list('A',data, 'time', 'sec',axis='N') 14 | 15 | # Prepare data and out data to col(B) 16 | data1=[x*1.5 for x in range(50)] 17 | wks.from_list('B', data1, axis='X') 18 | 19 | # Add a third column 20 | wks.cols=3 21 | 22 | # Use the sum of data and data1 to set the third column 23 | wks.from_list(2, [sum(i) for i in zip(data, data1)], comments = 'A+B') 24 | 25 | -------------------------------------------------------------------------------- /1. Origin-Python Data Exchange/Readme.md: -------------------------------------------------------------------------------- 1 | This folder contains examples showing data exchange between Python (list, dataframe, dictionary) and Origin objects ( workbook, matrixbook, project variables). 2 | 3 | -------------------------------------------------------------------------------- /1. Origin-Python Data Exchange/Worksheet User Tree Access.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to prepare a worksheet tree, and 3 | how to read the values back. This is useful to save the metadata 4 | of a data file. See the blog: 5 | https://blog.originlab.com/accessing-metadata-using-python 6 | ''' 7 | 8 | import originpro as op 9 | 10 | # Create a new worksheet and set worksheet tree values. 11 | wks = op.new_sheet() 12 | wks.set_str("tree.data.name", "Larry") 13 | wks.set_int("tree.data.age", 37) 14 | wks.set_float("tree.data.mean", 23.56) 15 | 16 | # access the tree as a dictionary 17 | dd = wks.userprops['data'] 18 | user=dd['name'] 19 | value=dd['age'] 20 | print(f'{user} is {value}') 21 | 22 | # you can also get the tree as an xml ElementTree for more advanced usage 23 | trWks = wks.usertree 24 | trData = trWks.find('data') 25 | for child in trData: 26 | print(f'{child.tag} = {child.text}') 27 | 28 | # how to put a modified tree to another sheet 29 | wk2 = op.new_sheet() 30 | age_node=trData.find('age') 31 | age_node.text='47' 32 | 33 | wk2.usertree=trWks 34 | print(wk2.userprops['data']['age']) 35 | -------------------------------------------------------------------------------- /2. Worksheet/Import CSV with Auto Settings.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to use from_file function to import text data to worksheet 3 | ''' 4 | import originpro as op 5 | 6 | f = op.path('e')+r'Samples\Curve Fitting\Enzyme.dat' 7 | 8 | #assume active worksheet 9 | wks = op.find_sheet() 10 | 11 | #By default, CSV connector is used 12 | wks.from_file(f) 13 | 14 | print(wks.shape) -------------------------------------------------------------------------------- /2. Worksheet/Import CSV with Selected Rows.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This example shows how to do partial import with CSV data connector 3 | ''' 4 | import originpro as op 5 | 6 | f = op.path('e')+r'Samples\Import and Export\S15-125-03.dat' 7 | wks = op.new_sheet() 8 | 9 | #Use CSV connector which is the default 10 | #and connector will be removed after import 11 | dc = op.Connector(wks) 12 | 13 | #Specify the rows to import 14 | ss = dc.settings() 15 | partial = ss['partial'] 16 | partial[op.attrib_key('Use')]='1' 17 | partial['row']='10:20' 18 | 19 | #import from rwo 10 to row 20 20 | dc.imp(f) 21 | 22 | 23 | -------------------------------------------------------------------------------- /2. Worksheet/Import Excel Sheet.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This example shows how to Customize the Excel data connector. 3 | 1. Parse headerlines to column labels. 4 | 2. Import partial cols and rows. 5 | 3. Specify the spreadsheet to import. 6 | ''' 7 | import originpro as op 8 | 9 | f = op.path('e')+r'Samples\Import and Export\Partial Import.xlsx' 10 | wks = op.new_sheet() 11 | 12 | #Create data connector object 13 | dc = op.Connector(wks, dctype='Excel', keep_DC=True) 14 | ss = dc.settings() 15 | 16 | #Headerlines to column label 17 | labels = ss['labels'] 18 | labels[op.attrib_key('Use')] = '1' 19 | labels['longname'] = 1 20 | labels['unit'] = 2 21 | 22 | #Setting for partial import 23 | partial = ss['partial'] 24 | partial[op.attrib_key('Use')] = '1' 25 | partial['col'] = '1:3' 26 | partial['row'] = '1:99' 27 | 28 | #Import the second spreadsheet 'expt2' 29 | dc.imp(f, sel='expt2') 30 | 31 | -------------------------------------------------------------------------------- /2. Worksheet/Import HTML Table from the Web.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Despite the name, from_file can actually import from the web 3 | This example shows using the HTML connector to import a specific table 4 | from a wikipedia web page 5 | ''' 6 | import originpro as op 7 | fn = 'https://en.wikipedia.org/wiki/World_population' 8 | wks=op.new_sheet() 9 | wks.from_file(fn, True, 'HTML', 'Tables/_6') 10 | 11 | -------------------------------------------------------------------------------- /2. Worksheet/Import MATLAB.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to import MATLAB file. 3 | You can try different selection by using GUI 4 | ''' 5 | 6 | import originpro as op 7 | fn = op.path('e')+r'Samples\Import and Export\GaussianData.mat' 8 | wks=op.new_sheet() 9 | 10 | wks.from_file(fn, True, 'MATLAB', 'MATLAB/Data') 11 | -------------------------------------------------------------------------------- /2. Worksheet/Import Multiple Files using Pandas into One Worksheet.py: -------------------------------------------------------------------------------- 1 | """ 2 | This shows import text files using DataFrame instead of Origin's internal import 3 | """ 4 | import originpro as op 5 | import pandas as pd 6 | import os 7 | fd = op.path('e') + r'Samples\Batch2' 8 | wks = op.new_sheet() 9 | col = 0 10 | for file in os.listdir(fd): 11 | df = pd.read_table(os.path.join(fd, file), header=[0,1,2]) 12 | wks.from_df(df, col) 13 | wks.cols_axis('xy', col) 14 | wks.set_labels(df.columns.get_level_values(0), 'L', col) 15 | wks.set_labels(df.columns.get_level_values(1), 'U', col) 16 | #the sample data file has no comment for X column, so we need to remove the 'Unnamed: 0_level_2' 17 | comments = df.columns.get_level_values(2).tolist() 18 | comments[0] = "" 19 | wks.set_labels(comments, 'C', col) 20 | col = wks.cols 21 | -------------------------------------------------------------------------------- /2. Worksheet/Import Two Excel Sheets.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This example shows how to import a second sheet from an Exel file with multiple sheets. 3 | ''' 4 | import originpro as op 5 | 6 | f = op.path('e')+r'Samples\Import and Export\United States Energy (1980-2013).xls' 7 | wks = op.new_sheet() 8 | 9 | #Create data connector object 10 | dc = op.Connector(wks, dctype='Excel', keep_DC=False) 11 | 12 | ss = dc.settings() 13 | #1st two rows are header, followed by column name and units 14 | ss['mainheader']=2; 15 | labels = ss['labels'] 16 | #labels branch use an attrtibute to turn on, so from a dict, 17 | #special node is needed to set internal tree attribute 18 | labels[op.attrib_key('Use')] = '1' 19 | labels['longname'] = 1 20 | labels['unit'] = 2 21 | 22 | #Import the first sheet, which is "oil" 23 | dc.imp(f, sel='Oil') 24 | 25 | #Import a new Excel sheet as a new Origin sheet 26 | dc.new_sheet('Natural Gas') 27 | 28 | -------------------------------------------------------------------------------- /2. Worksheet/Import Using a Filter.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This example shows how to use a filter created from Import Wizard 3 | ''' 4 | import originpro as op 5 | 6 | fn = op.path('e')+r'Samples\Import and Export\S15-125-03.dat' 7 | wks=op.new_sheet() 8 | #use a filter in the same folder as the data file 9 | wks.from_file(fn, False, 'Import Filter','.\VarsFromFileNameAndHeader.oif') 10 | -------------------------------------------------------------------------------- /2. Worksheet/Import by Setting File Header Info.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This example shows how to control file header. Typically the CSV connector can automatically 3 | detect main header and column header info, but sometimes the automatic detection does not work 4 | for certain file so you need to specify it yourself. 5 | ''' 6 | import originpro as op 7 | 8 | wks = op.new_sheet() 9 | dc = op.Connector(wks) 10 | dc.source = op.path('e')+r'Samples\Import and Export\F1.dat' 11 | ss = dc.settings() 12 | ss['mainheader']=5 13 | ss['heading']=1 14 | ss['unit']=2 15 | #must not pass in filepath if you are controlling file header 16 | #if file is passed in, the auto detection code will kick in to wipe out the settings above 17 | dc.imp() 18 | 19 | -------------------------------------------------------------------------------- /2. Worksheet/Manipulate Columns and Make Group Plot.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to prepare worksheet for plotting. 3 | ''' 4 | import originpro as op 5 | 6 | #Import Data File 7 | f = op.path('e')+r'Samples\Signal Processing\Sunspot.dat' 8 | wks = op.new_sheet() 9 | wks.from_file(f, keep_DC=False) 10 | 11 | #Set worksheet property 12 | wks.cols=5 13 | wks.move_cols(1,2,1) #Insert a date column 14 | wks.cols_axis('xyy',2,4) #Set column designation 15 | 16 | #Set "Date" column property 17 | ncol=2 18 | wks.set_formula(ncol,'date(B$ + "/1/" + A$)') 19 | wks.set_label(ncol, 'Date') 20 | wks.as_date(ncol,"yyyy/MM") 21 | 22 | #Set "Averaged Sunspot Number" column property 23 | ncol=4 24 | wks.set_formula(ncol,'movavg(D,20,20)') 25 | wks.set_label(ncol, 'Averaged Sunspot Number') 26 | 27 | #Plot "Sunspot Number" vs "Date" 28 | gp = op.new_graph() 29 | gp[0].add_plot(f'{wks.lt_range()}!(3,4:5)') # Plot using data range 30 | gp[0].group() 31 | gp[0].rescale() 32 | 33 | -------------------------------------------------------------------------------- /2. Worksheet/Readme.md: -------------------------------------------------------------------------------- 1 | This folder contains examples of data import, worksheet manipulation, calculation and graphing with **originpro** package. 2 | For worksheet related functions in **originpro**, see [worksheet](https://docs.originlab.com/originpro/classoriginpro_1_1worksheet_1_1WSheet.html). 3 | For project related functions, see [project](https://docs.originlab.com/originpro/namespaceoriginpro_1_1project.html). 4 | -------------------------------------------------------------------------------- /2. Worksheet/Split Dataset to Training and Testing Data.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This example splits a dataset with multiple columns to two datasets named Train and Test, 3 | using the package sklearn. To check for and install if needed, 4 | open the Script Window (Shift+Alt+3), type the following and press Enter. 5 | pip -chk pandas sklearn 6 | ''' 7 | import numpy as np 8 | import pandas as pd 9 | import originpro as op 10 | from sklearn.model_selection import train_test_split 11 | 12 | # Import data and get the independent and dependent data to X and y respectively 13 | ws=op.new_sheet() 14 | ws.from_file(fname=op.path('e')+r"Samples\Statistics\Fisher's Iris Data.dat", keep_DC=False) 15 | 16 | # Get first 4 columns as X 17 | X = ws.to_df(c1=0, numcols=4) 18 | 19 | # Get the last column as y 20 | y = ws.to_df(c1=4, numcols=1) 21 | 22 | # Split the dataset into train and test datasets 23 | # train dataset contains 70% samples, and test dataset contains 30% samples 24 | # shuffle the data before splitting 25 | X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, shuffle=True, random_state=1) 26 | 27 | # Create worksheet for the splitted datasets 28 | wks = op.new_sheet('w', 'Split') 29 | Num = X_train.columns.shape[0] 30 | wks.from_list(Num, y_train.iloc[:, 0].tolist(), comments='Train', lname=y_train.columns[0]) 31 | wks.from_list(Num*2+1, y_test.iloc[:, 0].tolist(), comments='Test', lname=y_train.columns[0]) 32 | for idx in range(Num): 33 | wks.from_list(idx, X_train.iloc[:, idx].tolist(), comments='Train', lname=X_train.columns[idx]) 34 | wks.from_list(Num+1+idx, X_test.iloc[:, idx].tolist(), comments='Test', lname=X_train.columns[idx]) -------------------------------------------------------------------------------- /3. Matrix/3D Parametric Plot From Matrix.py: -------------------------------------------------------------------------------- 1 | '''This sample shows how to plot parametric 3D surface from a matrix sheet.''' 2 | import originpro as op 3 | import numpy as np 4 | 5 | # Generate torus mesh 6 | angle = np.linspace(0, 2*np.pi, 32) 7 | theta, phi = np.meshgrid(angle, angle) 8 | r, R = .25, 1. 9 | X = (R + r * np.cos(phi)) * np.cos(theta) 10 | Y = (R + r * np.cos(phi)) * np.sin(theta) 11 | Z = r * np.sin(phi) 12 | arr_3D = np.stack([Z,X,Y], axis=0) # Stack X,Y,Z to get a 3D array 13 | 14 | # Pass the data to a matrix sheet and plot 15 | ms = op.new_sheet('m') 16 | ms.from_np(arr_3D) 17 | 18 | gp = op.new_graph(template='GLparafunc') 19 | gp[0].add_mplot(ms,0,1,2) 20 | gp[0].rescale('z') 21 | 22 | -------------------------------------------------------------------------------- /3. Matrix/Download GeoTIFF Image to Make Surface Plot.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Origin2023b or later is required to run this sample code. 3 | 4 | This example shows how to use Origin Image Window's ability to directly import an image using 5 | a URL address, which is not yet supported in a matrix window. Once image is downloaded into an 6 | Image Window, it can be converted to a matrix with the coordinates from the GeoTIFF retained. 7 | The sample also shows to download a graph template from Originlab to make our plot 8 | ''' 9 | import originpro as op 10 | #use the smaller 2-arc sec DEM available only for Alaska from National Map 11 | url = r'https://prd-tnm.s3.amazonaws.com/StagedProducts/Elevation/2/TIFF/historical/n59w154/USGS_2_n59w154_20210401.tif' 12 | iw=op.new_image() 13 | iw.from_file(url) 14 | #create an empty matrix and tranfer the image to it 15 | mat = op.new_book('m') 16 | mat[0].from_img(iw) 17 | #you may want to keep the image window and comment out the next line but 18 | #it is no longer needed to make the graph 19 | iw.destroy() 20 | #On Template Center dialog, click any template will open the weblink to see the fid 21 | #here 939 = RaisedReliefMap.otpu 22 | nn=op.olab_download(939) 23 | if nn < 0: 24 | if nn==-30: 25 | raise Exception("Your copy of Origin needs to be registered to download templates from Originlab website") 26 | 27 | raise Exception("Sorry, failed to download template from Originlab website") 28 | 29 | gp = op.new_graph(template='RaisedReliefMap') 30 | 31 | #we need to turn on speed mode and hide the speed mode banner 32 | gp.set_int('Banner', 0) 33 | gl = gp[0] 34 | gl.set_int('MatMaxPtsEnabled', 1) 35 | plot = gl.add_mplot(mat[0], 0) 36 | gl.rescale() 37 | 38 | #if template did not have clip data enabled 39 | #gl.set_int('clip',1) 40 | 41 | plot.colormap = 'Magma.PAL' 42 | ax=gl.axis('x') 43 | ax.sto=-153.2 44 | ay=gl.axis('y') 45 | ay.set_limits(58.4,59) 46 | 47 | gl.set_int('light.direction.h', 74) 48 | gl.set_int('light.direction.v', 27) 49 | 50 | -------------------------------------------------------------------------------- /3. Matrix/Import NetCDF with Partial Settings.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This example shows importing from the web and to specify from Jan of each year 3 | as well as doing proper longitude and latitude corrections. 4 | ''' 5 | import originpro as op 6 | mat = op.new_sheet('m') 7 | #you can actually use URL in from_file 8 | url = 'https://www.unidata.ucar.edu/software/netcdf/examples/tos_O1_2001-2002.nc' 9 | #keep the connector so after the import, you can click on the icon to 10 | #choose Options... to see open the dialog to see the details indicated by the sel string 11 | mat.from_file(url, True, dctype='NetCDF', sel='NetCDF/tos[1:0|1-11][y#][x/2]') 12 | -------------------------------------------------------------------------------- /3. Matrix/Matrix Dot Product using numpy.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows basic data transfer between Origin matrix and a NumPy array. 3 | Make sure you've installed pandas before trying the following sample. 4 | So to check for and install if needed, open the Script Window (Shift+Alt+3), 5 | type the following and press Enter: 6 | pip -chk pandas 7 | ''' 8 | import numpy as np 9 | import originpro as op 10 | 11 | #integer matrix data 12 | aa = np.array([ [1, 2, 3], [4, 5, 6] ]) 13 | bb = np.array([ [10,11], [20,21], [30,31] ]) 14 | 15 | #create a new hidden matrix book, and get the matrix sheet 16 | ma=op.new_sheet('m') 17 | 18 | #matrix sheet can hold a 3D array, shape and data type is automatically set 19 | ma.from_np(aa) 20 | 21 | #another sheet in same book 22 | mb = ma.get_book().add_sheet() 23 | mb.from_np(bb) 24 | 25 | #put result into 3rd sheet 26 | mc = ma.get_book().add_sheet('Dot Product') 27 | 28 | #do the actual calculation using numpy 29 | #here each sheet has only one matrix object, so we get it as 2d array 30 | cc = np.dot(ma.to_np2d(), mb.to_np2d()) 31 | mc.from_np(cc) 32 | 33 | -------------------------------------------------------------------------------- /3. Matrix/Plot Heatmap from Matrix.py: -------------------------------------------------------------------------------- 1 | '''This sample shows how to plot a heatmap from a matrix sheet.''' 2 | import originpro as op 3 | import numpy as np 4 | 5 | arr_2D = np.random.randint(0,4, size=(4,4)) 6 | ms = op.new_sheet('m') 7 | ms.from_np(arr_2D) 8 | ms.xymap = -3, 3, -3, 3 9 | gp = op.new_graph(template='heatmap') 10 | gp[0].add_plot(ms, colz=0) 11 | gp[0].rescale('z') 12 | #default XY scale will include the half width of each data point 13 | #so to have same scale as the matrix, we need to force it 14 | gp[0].set_xlim(-3, 3) 15 | gp[0].set_ylim(-3, 3) 16 | -------------------------------------------------------------------------------- /3. Matrix/Use OpenCV to Load TIFF Images into Matrix Sheet.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This example shows how to import tif images into a 3d numpy array and then pass into Origin matrix book. 3 | To install openCV (cv2), do the following from Script Window 4 | pip install opencv-python 5 | ''' 6 | import originpro as op 7 | import numpy as np 8 | import cv2 9 | 10 | # import tifs into array 11 | # Assume all images share the same dimesion 12 | ImArray = np.array([]) 13 | for idx in range(7): 14 | fname = op.path('e') + f'Samples\\Image Processing and Analysis\\myocyte{idx+1}.tif' 15 | array = np.array(cv2.imread(fname, cv2.IMREAD_UNCHANGED)) 16 | ImArray = np.dstack((ImArray, array)) if ImArray.size else array 17 | 18 | # put this 3d array into Origin Matrix Sheet 19 | ms = op.new_sheet('m') 20 | ms.from_np(arr=ImArray, dstack=True) 21 | ms.show_slider(True) 22 | ms.show_image(True) 23 | 24 | -------------------------------------------------------------------------------- /3. Matrix/readme.md: -------------------------------------------------------------------------------- 1 | This folder contains examples of matrix manipulation, calculation and graphing with **originpro** package. 2 | For matrix related functions in **originpro**, see [matrixsheet](https://docs.originlab.com/originpro/classoriginpro_1_1matrix_1_1MSheet.html). 3 | For project related functions, see [project](https://docs.originlab.com/originpro/namespaceoriginpro_1_1project.html). 4 | -------------------------------------------------------------------------------- /4. Graphing/Control Plots As Group.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample plots a whole worksheet as XY plot and control plots in group 3 | ''' 4 | import os 5 | import originpro as op 6 | 7 | wks = op.new_sheet() 8 | wks.from_file(os.path.join(op.path('e'), 'Samples', 'Graphing', 'Group.dat')) 9 | graph = op.new_graph(template='scatter') 10 | gl=graph[0] 11 | 12 | # plot whole sheet as XY plot 13 | plot = gl.add_plot(f'{wks.lt_range()}!(?,1:end)') 14 | 15 | # group the plots and control plots setting in group 16 | gl.group() 17 | plot.colormap = 'Candy' 18 | plot.shapelist = [3, 2, 1] 19 | gl.rescale() 20 | 21 | # Customize Legend 22 | lgnd = gl.label('Legend') 23 | lgnd.set_int('fsize', 22) 24 | lgnd.set_int('left',1400) 25 | lgnd.set_int('top',700) 26 | lgnd.set_int('showframe',0) -------------------------------------------------------------------------------- /4. Graphing/Custom Linked Axis.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to customize the linked axis to make a functionally mapped double-X graph 3 | ''' 4 | import originpro as op 5 | 6 | graph = op.new_graph() 7 | gl = graph[0] 8 | gl.axis('x').title='Fahrenheit' 9 | 10 | # add Top-X layer 11 | gl2 = graph.add_layer(1) 12 | 13 | # use LabTalk change top axis' title 14 | op.lt_exec('xt.text$=Celsius') 15 | 16 | # mapped Double-X, Fahrenheit to Celsius conversion 17 | gl2.set_str('x.link.from', '(X1-32)/1.8') 18 | gl2.set_str('x.link.to', '(X2-32)/1.8') 19 | gl2.set_int('x.showgrids',1) 20 | gl2.set_int('x.grid.majorType',2) 21 | 22 | # use temperature data to plot 23 | wks = op.new_sheet() 24 | wks.from_file(op.path('e')+r"Samples\Statistics\temperature.dat") 25 | gl.activate() 26 | gl.add_plot(wks, coly=1, colx=0, type='s') 27 | gl.rescale() -------------------------------------------------------------------------------- /4. Graphing/Customize Legend.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to customize the legend 3 | ''' 4 | import originpro as op 5 | 6 | wks = op.new_sheet() 7 | wks.from_file(op.path('e')+r"Samples\Graphing\Group.dat") 8 | 9 | # plot whole sheet as XY plot 10 | graph = op.new_graph(template='scatter') 11 | gl = graph[0] 12 | plot = gl.add_plot(f'{wks.lt_range()}!(?,1:end)') 13 | 14 | # group the plots and control plots setting in group 15 | gl.group() 16 | plot.colormap = 'Candy' 17 | plot.shapelist = [3, 2, 1] 18 | gl.rescale() 19 | 20 | # Customize Legend, use set_* function to set legend's LabTalk property 21 | lgnd = gl.label('Legend') 22 | lgnd.set_int('showframe', 0) 23 | 24 | # use x/y axis end value to set legend center x/y position 25 | xto = gl.get_float('x.to') 26 | yto = gl.get_float('y.to') 27 | lgnd.set_float('x', xto - lgnd.get_float('dx') / 2) 28 | lgnd.set_float('y', yto - lgnd.get_float('dy') / 2) 29 | -------------------------------------------------------------------------------- /4. Graphing/Customizing Graph.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to format graphs 3 | ''' 4 | import originpro as op 5 | 6 | # make a scatter plot 7 | wks = op.new_sheet() 8 | wks.from_file(op.path('e') + 'Samples\Graphing\Group.dat') 9 | graph = op.new_graph(template='Scatter') 10 | gl = graph[0] 11 | plot = gl.add_plot(wks, coly=1, colx=0) 12 | gl.rescale() 13 | 14 | # change layer background color 15 | # use set_* to access object's LabTalk property 16 | gl.set_int('color', 7) 17 | 18 | # change plot color 19 | plot.color = 2 20 | 21 | # show grid lines 22 | gl.set_int('x.showgrids',1) 23 | gl.set_int('y.showgrids',1) 24 | 25 | # show axis opposite line 26 | gl.set_int('x.opposite',1) 27 | gl.set_int('y.opposite',1) -------------------------------------------------------------------------------- /4. Graphing/Graph Legend to Show Only First Plot.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to make a multi-layer graph and show legend only on the top layer and to show 3 | only legend for the first plot, while each layer has 3 plots. 4 | ''' 5 | import os 6 | import originpro as op 7 | 8 | # Input three data files into three worksheets within one workbook 9 | wb = op.new_book() 10 | wb.set_int('nLayers',3) # Set number of sheets 11 | for wks, fn in zip(wb, ['S15-125-03.dat', 'S21-235-07.dat', 'S32-014-04.dat']): 12 | wks.from_file(os.path.join(op.path('e'), 'Samples', 'Import and Export', fn)) 13 | 14 | # Add data plots onto the graph 15 | gp = op.new_graph(template='PAN2VERT') # load Vertical 2 Panel graph template 16 | 17 | # Loop over layers and worksheets to add individual curve. 18 | for i, gl in enumerate(gp): 19 | for wks in wb: 20 | plot = gl.add_plot(wks,1+i) 21 | gl.group() 22 | gl.rescale() 23 | 24 | # Customize legend 25 | lgnd = gp[1].label('Legend') 26 | 27 | lgnd.set_int('left',4900) 28 | lgnd.set_int('top',100) 29 | #must have something different from internal "\l(1) %(1)" to prevent auto expending 30 | #so I just added a space, but you can add a caption or whatever as long as it is 31 | #different from the generic internal form 32 | lgnd.text=' \l(1) %(1)' 33 | 34 | #we only need one legend, so the one in layer1 will not be needed 35 | gp[0].label('Legend').remove() 36 | -------------------------------------------------------------------------------- /4. Graphing/Line Plot with Log Scale.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample creates a sample signal and uses this package to create a periodogram power spectral density plot. 3 | This example requires certain Python packages. To check for and install if needed, 4 | open the Script Window (Shift+Alt+3), type the following and press Enter: 5 | pip -chk scipy numpy 6 | ''' 7 | import numpy as np 8 | from scipy import signal 9 | import originpro as op 10 | 11 | # periodogram power spectral density 12 | fs = 10e3 13 | N = 1e5 14 | amp = 2*np.sqrt(2) 15 | freq = 1234.0 16 | noise_power = 0.001 * fs / 2 17 | time = np.arange(N) / fs 18 | x = amp*np.sin(2*np.pi*freq*time) 19 | x += np.random.normal(scale=np.sqrt(noise_power), size=time.shape) 20 | f, Pxx_den = signal.periodogram(x, fs) 21 | 22 | # put the data into worksheet 23 | wks = op.new_sheet(type='w', lname='Periodogram Power Spectral') 24 | wks.from_list(0, f, lname='Freq', units='Hz') 25 | wks.from_list(1, Pxx_den, lname='PSD', units='V\+(2)/Hz') 26 | 27 | graph = op.new_graph(template='line') 28 | 29 | #log scale 30 | graph[0].yscale = 2 31 | 32 | graph[0].set_xlim(begin=0, end=5000, step=1000) 33 | 34 | #step=2 in log 35 | graph[0].set_ylim(1e-7, 1e2, 2) 36 | 37 | graph[0].label('legend').remove() 38 | 39 | #page.aa in LT, anti-alias -> On 40 | graph.set_int('aa', 1) 41 | 42 | # plot the data into the graph 43 | plot = graph[0].add_plot(wks, coly=1, colx=0, type='line') 44 | plot.color = '#167BB2' -------------------------------------------------------------------------------- /4. Graphing/Merge Graphs.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to merge Graph1, Graph2...... Graph10 3 | ''' 4 | import originpro as op 5 | 6 | ids = list(range(1,11)) 7 | graphs = ["Graph" + str(i) for i in ids] 8 | graphs = '\n'.join(graphs) 9 | 10 | ltStr = f'merge_graph option:=specified option:=specified graphs:="{graphs}" row:=2 col:=5;' 11 | op.lt_exec(ltStr) -------------------------------------------------------------------------------- /4. Graphing/Multiple Layer Plot.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to make multi-layer graph with Python 3 | where data on each layer is from different worksheet. Legend 4 | is customized to show sheet name. 5 | ''' 6 | import os 7 | import originpro as op 8 | 9 | # Input three data files into three worksheets within one workbook 10 | wb = op.new_book() 11 | wb.set_int('nLayers',3) # Set number of sheets 12 | for wks, fn in zip(wb, ['S15-125-03.dat', 'S21-235-07.dat', 'S32-014-04.dat']): 13 | wks.from_file(os.path.join(op.path('e'), 'Samples', 'Import and Export', fn)) 14 | 15 | # Add data plots onto the graph 16 | gp = op.new_graph(template='PAN2VERT') # load Vertical 2 Panel graph template 17 | 18 | # Loop over layers and worksheets to add individual curve. 19 | for i, gl in enumerate(gp): 20 | for wks in wb: 21 | plot = gl.add_plot(wks,1+i) 22 | gl.group() 23 | gl.rescale() 24 | 25 | # Customize legend 26 | lgnd = gp[1].label('Legend') 27 | lgnd.text='\l(1) %(1, @ws)\n\l(2) %(2, @ws)\n\l(3) %(3, @ws)' 28 | lgnd.set_int('left',4900) 29 | lgnd.set_int('top',100) 30 | 31 | gp[0].label('Legend').remove() -------------------------------------------------------------------------------- /4. Graphing/Plot Contour and 3D Surface Graph.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to plot contour and 3D colormap surface from XYZ data. 3 | The Graph template names and IDs can be found in the page: 4 | https://www.originlab.com/doc/LabTalk/ref/Plot-Type-IDs 5 | ''' 6 | import originpro as op 7 | 8 | #Import Data File 9 | wks = op.new_sheet() 10 | f = op.path('e')+r'Samples\Matrix Conversion and Gridding\XYZ Random Gaussian.dat' 11 | wks.from_file(f) 12 | wks.cols_axis('xyz') 13 | 14 | # Plot 3D surface 15 | gp = op.new_graph(template='glCMAP') 16 | p = gp[0].add_plot(wks,coly=1,colx=0,colz=2, type=103) 17 | gp[0].rescale() 18 | 19 | # Plot contour 20 | gp = op.new_graph(template='TriContour') 21 | p = gp[0].add_plot(wks,coly=1,colx=0,colz=2, type=243) 22 | p.colormap = 'Maple.pal' 23 | gp[0].rescale() -------------------------------------------------------------------------------- /4. Graphing/Plot From Data Range.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to use data range to make plot. 3 | ''' 4 | import os 5 | import originpro as op 6 | 7 | # Import the data file 8 | wks = op.new_sheet() 9 | wks.from_file(os.path.join(op.path('e'), 'Samples', 'Statistics', 'ANOVA', 'One-Way_ANOVA_indexed.dat')) 10 | 11 | # Create a graph page 12 | graph = op.new_graph(template='scatter') 13 | gl=graph[0] 14 | 15 | # Use the data range string as add_plot() argument. 16 | plot = gl.add_plot(f'{wks.lt_range()}!(1,3)[1:20]') 17 | plot = gl.add_plot(f'{wks.lt_range()}!(1,3)[21:40]') 18 | plot = gl.add_plot(f'{wks.lt_range()}!(1,3)[41:60]') 19 | 20 | gl.group() 21 | gl.rescale() 22 | 23 | # Customize legend 24 | lgnd = gl.label('Legend') 25 | lgnd.text='\l(1) class 1 \l(2) class 2 \l(3) class 3' 26 | lgnd.set_int('left',1400) 27 | lgnd.set_int('showframe',0) 28 | -------------------------------------------------------------------------------- /4. Graphing/Plot Heatmap from Matrix Data.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to plot a heatmap from matrix data 3 | It also shows how to set matrix xy map, color scale title and how to set plot colormap 4 | ''' 5 | import originpro as op 6 | import numpy as np 7 | 8 | arr = np.array([[1, -8], [3, -4], [5, 4], [7, 8]]) 9 | mat = op.new_sheet(type='m') 10 | mat.from_np(arr) 11 | #set the 1st matrix's long name, which is the Z lable, which the color scale will use as title 12 | mat.set_label(0, 'Z Levels') 13 | #set the XY mapping in the matrix which will provde the XY scale for the graph 14 | x1,x2,y1,y2 = 0.5, 2.5, 0.5, 4.5 15 | mat.xymap = x1,x2,y1,y2 16 | gr = op.new_graph(template='Heat_Map.otpu') 17 | g = gr[0] 18 | p = g.add_mplot(mat, 0, type = 105) 19 | #heatmap is showing data point at the center, so need to adjust for half step size 20 | hs = 0.5 * (x2-x1)/2; 21 | g.set_ylim(y1-hs, y2+hs, 1) 22 | g.set_xlim(x1-hs, x2+hs, 1) 23 | #set plot colormap 24 | z = p.zlevels 25 | z['minors'] = 15 26 | z['levels'] = [-8, 0, 8] 27 | p.zlevels = z 28 | p.colormap = 'BlueYellow.pal' 29 | -------------------------------------------------------------------------------- /4. Graphing/Plot Symbols Indexed by Column Values.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample creates a scatter plot from the A(x) B(y) and control plot symbols from: 3 | col(C) = color index (1=black,2=red etc), offset = 1 from Y which is col(B) 4 | col(D) or col(4), or offset=2 from col(B) = symbol type and so on 5 | modi_col is for genreal modifier control 6 | color_col is specific to color which can further control color types, index, direct RGB, colormap 7 | ''' 8 | import originpro as op 9 | wks = op.new_sheet(); 10 | wks.cols=6 11 | x=[1,2,3,4,5] 12 | for i in range(6): 13 | wks.from_list(i,x) 14 | 15 | graph = op.new_graph(template='scatter') 16 | layer = graph[0] 17 | plot = layer.add_plot(wks, coly=1, colx=0) 18 | layer.rescale() 19 | plot.color = op.color_col(1, 'n')# the +1 column, n=index 20 | plot.symbol_kind = op.modi_col(2) 21 | plot.symbol_size = op.modi_col(3) 22 | plot.symbol_sizefactor=10 23 | plot.symbol_interior = op.modi_col(4) 24 | 25 | -------------------------------------------------------------------------------- /4. Graphing/Plotting 2D Contour Plot via Virtual Matrix.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to use virtual matrix to make a contour plot 3 | ''' 4 | import originpro as op 5 | 6 | # new a graph with Contour template 7 | gp = op.new_graph(template='Contour') 8 | 9 | # prepare data 10 | wks = op.new_sheet() 11 | wks.from_file(op.path('e')+"Samples\Graphing\VSurface 1.dat") 12 | 13 | # use LabTalk call plotvm X-Function 14 | # 226 = IDM_PLOT_CONTOUR 15 | # add plot to gp's first layer 16 | ltStr = r'plotvm irng:=1! format:=xacross rowpos:=selrow1 colpos:=selcol1 ztitle:="VSurface 1" type:=226 ogl:='+ f'{gp[0]}!' 17 | op.lt_exec(ltStr) 18 | 19 | # set X scale type to Log10 20 | gp.activate() 21 | gp[0].xscale=2 22 | gp[0].set_xlim(11, 100) 23 | gp[0].set_ylim(3, 7) -------------------------------------------------------------------------------- /4. Graphing/Readme.md: -------------------------------------------------------------------------------- 1 | This folder contains examples of plotting and customizing graphs with Python **originpro** package. 2 | 3 | For the graph related functions in **originpro**, see [Graph](https://www.originlab.com/python/doc/originpro/namespaceoriginpro_1_1graph.html). 4 | -------------------------------------------------------------------------------- /4. Graphing/Stacked Column Plot.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to make a stacked cloumn plots 3 | ''' 4 | import originpro as op 5 | 6 | # import data 7 | wks = op.new_sheet() 8 | wks.from_file(op.path('e') + 'Samples\Graphing\Group.dat') 9 | 10 | # add plots and group the plots 11 | graph = op.new_graph(template='StackColumn') 12 | gl = graph[0] 13 | gl.add_plot(wks, coly=1, colx=0, type='?') 14 | gl.add_plot(wks, coly=2, colx=0, type='?') 15 | gl.group(True, 0, 1) 16 | 17 | # set stack offset of plots to Cumulative 18 | gl.lt_exec('layer -b s 1') 19 | 20 | # set column plot gap 21 | gl.lt_exec('set %C -vg 40') -------------------------------------------------------------------------------- /5. Analysis/Batch Fitting Multiple Data Files.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample is to show how to run gaussian peak fit on multiple data files. 3 | Then the fitted peak parameters xc, w, A are plotted as a function of temperature 4 | in a three Y axes graph. 5 | ''' 6 | 7 | import originpro as op 8 | import numpy as np 9 | 10 | # One worksheet for imported data, one worksheet for peak fitting result 11 | wks = op.new_sheet() 12 | wks_result = op.new_sheet() 13 | 14 | 15 | wts = [0, 25, 100, 150, 250] 16 | for i, wt in enumerate(wts): 17 | # Import each data file into wks 18 | fd = op.path('e') + 'Samples\Batch2' 19 | fn = f'{fd}\Sample 2 {wt} wt.txt' 20 | wks.from_file(fn, keep_DC=False) 21 | 22 | # Baseline subtraction 23 | spec = wks.to_list(1) 24 | spec = np.array(spec) 25 | base = np.linspace(spec[0], spec[-1], len(spec)) # straight line connecting start and end point as baseline 26 | spec = spec - base 27 | wks.from_list(1, spec) 28 | 29 | # Run Gaussian fit on subtracted spectrum 30 | model = op.NLFit('Gaussian') 31 | model.set_data(wks, 0, 1) 32 | model.fix_param('y0',0) 33 | model.fit() 34 | ret = model.result() 35 | 36 | # Fitting result is saved to each row of wks_result 37 | wks_result.from_list2([wt, ret['xc'], ret['w'], ret['A'], ret['adjr']], i) 38 | 39 | wks_result.set_labels(['temperature','fit x','fit width', 'fit area', 'Adj. R-Square']) 40 | 41 | # Plot the data 42 | gp = op.new_graph(template='3Ys_Y-YY') 43 | for i in range(3): 44 | gp[i].add_plot(wks_result,1+i,0) 45 | gp[i].rescale() 46 | 47 | # Customize Legend 48 | lgnd = gp[0].label('Legend') 49 | lgnd.text='\l(1.1) %(1.1) \l(2.1) %(2.1) \l(3.1) %(3.1)' 50 | lgnd.set_int('fsize', 27) 51 | lgnd.set_int('top', 400) -------------------------------------------------------------------------------- /5. Analysis/Extract Values from NLFit Report Tables.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to use report_table function to 3 | access a table in an Analysis Report Sheet 4 | ''' 5 | import originpro as op 6 | import pandas as pd 7 | import os 8 | import re 9 | 10 | # Load analysis template book that ships with Origin. 11 | at = op.load_book(op.path('e') + r'Samples\Batch Processing\Sensor Analysis.ogw') 12 | 13 | # Get 1st worksheet in book. 14 | wks = at[0] 15 | wks_table = at[1] 16 | df_list = [] 17 | 18 | # Get folder for data files that ship with Origin. 19 | data_folder = op.path('e') + r'Samples\Curve Fitting' 20 | 21 | # Iterate data file folder for file names to import. 22 | for file in os.listdir(data_folder): 23 | 24 | # Filter for specific data files. 25 | if re.search('^Sensor[0-9]{2}.dat$', file): 26 | 27 | # Full path to file to import. 28 | imp_file = os.path.join(data_folder, file) 29 | 30 | # Import the file into the worksheet and removing the Data Connector. 31 | wks.from_file(imp_file, False) 32 | 33 | # Wait for analysis operation to complete. 34 | op.wait() 35 | 36 | # If you want to see live updates of the graph, add the line below. 37 | #op.wait('s', 0.1) 38 | 39 | df = wks_table.report_table('Summary') 40 | df.iloc[:, 0] = file 41 | 42 | df_list.append(df) 43 | 44 | print(f'working on {file}') 45 | 46 | result = pd.concat(df_list) 47 | wks_result = op.new_sheet() 48 | wks_result.from_df(result) 49 | 50 | -------------------------------------------------------------------------------- /5. Analysis/Fit 2 Indepedents and 2 Dependents.py: -------------------------------------------------------------------------------- 1 | import originpro as op 2 | wks = op.new_sheet() 3 | fn=op.path('e') + 'Samples\Curve Fitting\Enzyme2.dat' 4 | wks.from_file(fn, False) 5 | wks.cols_axis('x',2,2) 6 | 7 | #Specify the input data range, which follows 8 | #the independent/dependent order in FDF (x1, x2, v1, v2) 9 | range=f'{wks.lt_range()}!(1,3,2,4)' 10 | model = op.NLFit('HillBurk') 11 | model.set_range(range) 12 | model.fit() 13 | model.report(True) 14 | 15 | -------------------------------------------------------------------------------- /5. Analysis/Linear Regression and Plot.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample is to show how to run linear regression with Python in Origin. The fitted curve 3 | and prediction band are then plotted out. 4 | ''' 5 | 6 | import originpro as op 7 | 8 | # Import data file 9 | wb = op.new_book() 10 | wks = wb[0] 11 | fn=op.path('e') + 'Samples\Curve Fitting\Linear Fit.dat' 12 | wks.from_file(fn,False) 13 | 14 | #Perform linear fit 15 | lr = op.LinearFit() 16 | lr.set_data(wks, 0, 1) 17 | lr.fix_intercept(-0.7) 18 | r, c = lr.report(3) # Return the result report sheet and fitted curve sheet. 19 | wReport=op.find_sheet('w', r) 20 | wCurves=op.find_sheet('w', c) 21 | 22 | # Plot the data and fitted curve and confidence band 23 | gp = op.new_graph() 24 | gl = gp[0] 25 | 26 | # Plot data as scatter plot 27 | pltdata = gl.add_plot(wks, 1, 0, type='s') 28 | 29 | # Add the confidence band 30 | conf = gl.add_plot(wCurves, 2, 0) 31 | gl.add_plot(wCurves, 3, 0) 32 | 33 | # Group the newly added plots, starting from 1 to skip the scatter data 34 | gl.group(True, 1) 35 | conf.colorinc=0 36 | conf.transparency = 80 37 | conf.set_fill_area(op.ocolor('Red')) # fill the color to the next plot 38 | 39 | gl.add_plot(wCurves, 1, 0) # Plot the fitted line 40 | 41 | gl.rescale() 42 | 43 | # Customize legend 44 | lgnd = gl.label('Legend') 45 | lgnd.text='\\l(4) Linear Fit\n\\l(2) Confidence Band' 46 | lgnd.set_int('left',1400) 47 | lgnd.set_int('top',700) 48 | lgnd.set_int('showframe',0) 49 | -------------------------------------------------------------------------------- /5. Analysis/Load and Run Multiple Linear Fit Templates.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Import each data file in a sample folder into an Analysis Template and 3 | perform the fitting and update the reports with graphs, so you end up 4 | with a book for each file in the Origin workspace for further examination 5 | ''' 6 | import originpro as op 7 | import pandas as pd 8 | import os 9 | import re 10 | 11 | 12 | # location of sample data files that ship with Origin. 13 | data_folder = op.path('e') + r'Samples\Curve Fitting' 14 | 15 | # Iterate data file folder for file names to import. 16 | for file in os.listdir(data_folder): 17 | if re.search('^Sensor[0-9]{2}.dat$', file): 18 | print(f'working on {file}') 19 | imp_file = os.path.join(data_folder, file) 20 | # Load analysis template book that ships with Origin. 21 | at = op.load_book(op.path('e') + r'Samples\Batch Processing\Sensor Analysis.ogw') 22 | # This template put Data sheet as 1st worksheet in book. 23 | wks = at[0] 24 | # Import the file into the worksheet and removing the Data Connector. 25 | wks.from_file(imp_file, False) 26 | 27 | # Wait for analysis operation to complete. 28 | op.wait() 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /5. Analysis/Open Dialog for Interactive Control of the Fitting.py: -------------------------------------------------------------------------------- 1 | """ 2 | Fitting a curve on a graph and open dialog to adjust the parameters before final fitting 3 | """ 4 | import originpro as op 5 | 6 | wks = op.new_sheet() 7 | fn=op.path('e') + 'Samples\Curve Fitting\Gaussian.dat' 8 | wks.from_file(fn, False) 9 | graph = op.new_graph(template='scatter') 10 | gl=graph[0] 11 | dp = gl.add_plot(wks, 1, 0) 12 | gl.rescale() 13 | 14 | model = op.NLFit('Gauss') 15 | model.set_range(dp.lt_range()) 16 | """ 17 | dialog is modal, so wont close until OK, but you can use Minimize button 18 | to rollup the dialog and interact with the graph, then click Minimize again 19 | to open the dialog to continue 20 | """ 21 | model.param_box() 22 | #after the dialog, still need to call Fit for final processing 23 | model.fit() 24 | rr=model.result() 25 | #accessing parameters and errors 26 | xc=rr['xc'] 27 | xc_err=rr['e_xc'] 28 | #accessing other fitting stats 29 | chisqr=rr['chisqr'] 30 | adjr=rr['adjr'] 31 | print(f'AdjR2={adjr}, xc={xc}+-{xc_err}') 32 | -------------------------------------------------------------------------------- /5. Analysis/Sequential Fit Multiple Files.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Import each data file in a sample folder into and perform fitting with parameters dialog 3 | to check each fit and generate a sheet with result parameters and stats. 4 | ''' 5 | import originpro as op 6 | import os 7 | 8 | data_folder = op.path('e') + r'Samples\Batch Processing' 9 | #only to process 3 files 10 | names = ['T285K.csv', 'T305K.csv', 'T345K.csv'] 11 | pk_centers=[] 12 | Rsqrs=[] 13 | wdata = op.new_sheet() 14 | graph = op.new_graph(template='scatter') 15 | gl=graph[0] 16 | model = op.NLFit('Gauss') 17 | show_hint=True 18 | for file in names: 19 | f = os.path.join(data_folder, file) 20 | print(f'working on {f}') 21 | wdata.from_file(f, False) 22 | dp = gl.add_plot(wdata, 1, 0) 23 | gl.rescale() 24 | model.set_range(dp.lt_range()) 25 | if show_hint: 26 | op.messagebox('You can click the Minimize button on the Parameters Dialog to manipulate the graph') 27 | show_hint = False 28 | model.param_box() 29 | model.fit() 30 | 31 | if not op.messagebox('Take a look at the fit', True): 32 | model.result()#must call either result or report to end the fitting 33 | break 34 | 35 | rr=model.result() 36 | gl.remove(dp) 37 | Rsqrs.append(rr['adjr']) 38 | pk_centers.append(rr['xc']) 39 | 40 | wdata.get_book().destroy() 41 | graph.destroy() 42 | wks = op.new_sheet() 43 | wks.from_list(0, names, 'File Name') 44 | wks.from_list(1, pk_centers, 'Peak Center') 45 | wks.from_list(2, Rsqrs, 'R-sqr') 46 | -------------------------------------------------------------------------------- /5. Analysis/Simple Curve Fit on a Graph.py: -------------------------------------------------------------------------------- 1 | """ 2 | Simple example of doing a non-linear fitting with a report sheet 3 | """ 4 | import originpro as op 5 | 6 | wks = op.new_sheet() 7 | fn=op.path('e') + 'Samples\Curve Fitting\Gaussian.dat' 8 | wks.from_file(fn, False) 9 | graph = op.new_graph(template='scatter') 10 | gl=graph[0] 11 | dp = gl.add_plot(wks, 1, 0) 12 | gl.rescale() 13 | 14 | #do the fitting and generate report 15 | model = op.NLFit('Gauss') 16 | model.set_range(dp.lt_range()) 17 | model.fit() 18 | r, c = model.report() 19 | wReport=op.find_sheet('w', r) 20 | wReport.activate() 21 | -------------------------------------------------------------------------------- /5. Analysis/Simple Curve Fit to XY Data.py: -------------------------------------------------------------------------------- 1 | """ 2 | Simple example of doing a non-linear fitting without creating report sheet 3 | """ 4 | import originpro as op 5 | 6 | wks = op.new_sheet() 7 | fn=op.path('e') + 'Samples\Curve Fitting\Gaussian.dat' 8 | wks.from_file(fn, False) 9 | 10 | 11 | #do the fitting and receive fitting parameters. No report will be generated 12 | model = op.NLFit('Gauss') 13 | model.set_data(wks, 0, 1) 14 | model.fix_param('y0', 0) 15 | model.fit() 16 | rr=model.result() 17 | 18 | #accessing parameters and errors 19 | xc=rr['xc'] 20 | xc_err=rr['e_xc'] 21 | #accessing other fitting stats 22 | chisqr=rr['chisqr'] 23 | adjr=rr['adjr'] 24 | 25 | print(f'xc={xc}+-{xc_err}') 26 | 27 | -------------------------------------------------------------------------------- /5. Analysis/Simple Curve Fit with Report.py: -------------------------------------------------------------------------------- 1 | """ 2 | Simple example of doing a non-linear fitting with a report sheet 3 | """ 4 | import originpro as op 5 | 6 | wks = op.new_sheet() 7 | fn=op.path('e') + 'Samples\Curve Fitting\Gaussian.dat' 8 | wks.from_file(fn, False) 9 | 10 | #do the fitting and generate report 11 | model = op.NLFit('Gauss') 12 | model.set_data(wks, 0, 1) 13 | model.fit() 14 | r, c = model.report() 15 | wReport=op.find_sheet('w', r) 16 | wReport.activate() 17 | 18 | -------------------------------------------------------------------------------- /5. Analysis/Tabulate Multiple Nonlinear Fit Results.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample is to show how to run non-linear regression on multiple datasets and output 3 | the fitted result. 4 | ''' 5 | 6 | import originpro as op 7 | import pandas as pd 8 | 9 | # Import data file 10 | wb = op.new_book() 11 | wks = wb[0] 12 | fn=op.path('e') + 'Samples\Curve Fitting\Step01.dat' 13 | wks.from_file(fn, dctype='Import Filter') 14 | 15 | # Perform nonlinear curve fit on each dataset 16 | model = op.NLFit('Asymptotic1') 17 | nn = int(wks.cols/2) 18 | result = [] 19 | for i in range(nn): 20 | col_name = wks.get_label(2*i, 'L') 21 | model.set_data(wks, 2*i, 2*i+1) 22 | model.fit() 23 | ret = model.result() 24 | result.append([col_name, ret['a'], ret['b'], ret['c'], ret['adjr']]) 25 | df = pd.DataFrame(result, columns=['data','fit a','fit b', 'fit c', 'Adj. R-Square']) 26 | 27 | # Generate the result 28 | wks = op.new_sheet(lname='Result') 29 | wks.from_df(df) 30 | -------------------------------------------------------------------------------- /5. Analysis/readme.md: -------------------------------------------------------------------------------- 1 | This folder contains examples of performing curve fitting and generating analysis report with **originpro** package. 2 | -------------------------------------------------------------------------------- /6. Images/Accessing Individual Image in an Image Stack.py: -------------------------------------------------------------------------------- 1 | import originpro as op 2 | import numpy as np 3 | from skimage.util import invert 4 | #load image stack 5 | fn = op.path('e') + r'Samples\Image Processing and Analysis\*.tif' 6 | iw=op.new_image() 7 | iw.from_file(fn) 8 | print(iw.frames) 9 | #get the 3rd image 10 | im2 = iw.to_np2d(2) 11 | im2 *= 2 12 | im2 = np.invert(im2) 13 | #put it back into 2nd image 14 | iw.from_np2d(im2, 1) 15 | #show thumbnails 16 | iw.set_int('NAV',1) 17 | iw.set_str('Palette', 'Fire') 18 | -------------------------------------------------------------------------------- /6. Images/Image Split and Merge Channels.py: -------------------------------------------------------------------------------- 1 | import originpro as op 2 | 3 | fn = op.path('e') + r'Samples\Image Processing and Analysis\Leaves.jpg' 4 | iw=op.new_image() 5 | iw.from_file(fn) 6 | iw.split() 7 | g = iw.to_np2d(1) 8 | g *= 0 9 | iw.from_np2d(g, 1) 10 | iw.merge() 11 | iw.lname='Green is removed' 12 | 13 | -------------------------------------------------------------------------------- /6. Images/Image Window Basics.py: -------------------------------------------------------------------------------- 1 | import originpro as op 2 | #single image 3 | fn = op.path('e') + r'Samples\Image Processing and Analysis\car.bmp' 4 | iw=op.new_image() 5 | iw.from_file(fn) 6 | print(f'channels {iw.channels}, size {iw.size}, type {iw.type}') 7 | iw.rgb2gray() 8 | print(f'after convert to grayscale, channels {iw.channels}, frames {iw.frames}') 9 | 10 | #load multiple as image stack 11 | fn2 = op.path('e') + r'Samples\Image Processing and Analysis\*.tif' 12 | iw2=op.new_image() 13 | iw2.from_file(fn2) 14 | print(f'channels {iw2.channels}, size {iw2.size}, type {iw2.type}, frames {iw2.frames}') 15 | #show image thumbnails(1), 2=play control, 3=slider 16 | if iw2.type > 1: 17 | iw2.set_int('NAV', 1) 18 | 19 | -------------------------------------------------------------------------------- /6. Images/Image thinning with opencv.py: -------------------------------------------------------------------------------- 1 | #recommand to install "opencv-python-headless" 2 | import cv2 3 | import numpy as np 4 | import originpro as op 5 | 6 | fn = op.path('e') + r'Samples\Image Processing and Analysis\car.bmp' 7 | iw=op.new_image() 8 | iw.from_file(fn) 9 | iw.lname='original image' 10 | iw.rgb2gray() 11 | #make a copy to put result 12 | iw2=iw.duplicate() 13 | iw2.lname = 'thinning result' 14 | img = iw2.to_np() 15 | # Structuring Element 16 | kernel = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3)) 17 | # Create an empty output image to hold values 18 | thin = np.zeros(img.shape,dtype='uint8') 19 | 20 | # Loop until erosion leads to an empty set or max 21 | max = 20 22 | while (cv2.countNonZero(img)!=0): 23 | # Erosion 24 | erode = cv2.erode(img,kernel) 25 | # Opening on eroded image 26 | opening = cv2.morphologyEx(erode,cv2.MORPH_OPEN,kernel) 27 | # Subtract these two 28 | subset = erode - opening 29 | # Union of all previous sets 30 | thin = cv2.bitwise_or(subset,thin) 31 | # Set the eroded image for next iteration 32 | img = erode.copy() 33 | max -= 1 34 | if max == 0: 35 | break 36 | 37 | iw2.from_np(thin) 38 | -------------------------------------------------------------------------------- /6. Images/Inverting an Image with skimage.py: -------------------------------------------------------------------------------- 1 | #need to install "scikit-image" first 2 | import originpro as op 3 | import numpy as np 4 | from skimage.util import invert 5 | 6 | fn = op.path('e') + r'Samples\Image Processing and Analysis\Flower.jpg' 7 | iw=op.new_image() 8 | iw.from_file(fn) 9 | iw.lname='original image' 10 | #make a copy to put result 11 | iw2=iw.duplicate() 12 | iw2.lname='inverted' 13 | img = iw2.to_np() 14 | inv = invert(img) 15 | iw2.from_np(inv) 16 | #put into new empty image window 17 | iw3=op.new_image() 18 | #need to first setup the image window as 3 channels and not multi-frames 19 | iw3.setup(3,False) 20 | iw3.lname='invert back' 21 | inv = invert(inv) 22 | iw3.from_np(inv) 23 | 24 | -------------------------------------------------------------------------------- /6. Images/Load Digits Dataset from scikit-learn.py: -------------------------------------------------------------------------------- 1 | 2 | import originpro as op 3 | from sklearn.datasets import load_digits 4 | digits = load_digits() # load digit images, total 1797 images, each is 8x8 5 | aa = digits.images.astype(dtype='uint8') 6 | iw = op.new_image() 7 | iw.setup(1, True) # set image window is gray scale, with multiple frames 8 | data = aa[0:10,:,:] 9 | iw.from_np(data, False) 10 | iw.set_int('GrayMax',16) #set to show only 17 colors (0-16) 11 | iw.set_int('nav', 3) # Show navigation bar as slider 12 | iw.set_str('Palette', 'Fire') 13 | -------------------------------------------------------------------------------- /7. Miscellaneous/Close All Graphs at once.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows how to close all graphs at once by LabTalk script 3 | ''' 4 | import originpro as op 5 | 6 | # doc -e: execute the script in {} for all graph window (LP) 7 | # win -cp: post a message to close the window 8 | op.lt_exec("doc -e LP {win -cp %H}") -------------------------------------------------------------------------------- /7. Miscellaneous/Export Graphs as Images from Sample Projects.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample generate an image from a graph from a sample project. 3 | Please note that a file named my_py_test.png will be replaced by running this sample. 4 | ''' 5 | import originpro as op 6 | 7 | #from Learning Center folder 8 | op.open(op.path('c')+ r'\Graphing\Multi-Panel Graphs - Trellis Box Plot.opju') 9 | 10 | gg=op.find_graph(0) 11 | 12 | # export graph to an image 13 | f='' 14 | if gg: 15 | f=gg.save_fig(op.path()+'my_py_test.png',width=500) 16 | 17 | import os 18 | if len(f): 19 | os.startfile(f) -------------------------------------------------------------------------------- /7. Miscellaneous/Extract Image Colors.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample picks all colors from an image. 3 | The RGB values for each color is output to a worksheet. 4 | This example requires Python package extcolors to be preinstalled. 5 | ''' 6 | import extcolors 7 | import numpy as np 8 | import originpro as op 9 | 10 | # choose an image to extract colors 11 | file_path = op.file_dialog('*.png;*.jpg;*.bmp','Select an Image') 12 | if len(file_path) ==0: 13 | raise ValueError('user cancel') 14 | 15 | colors = extcolors.extract_from_path(file_path) 16 | 17 | # rgb = colors[:,0] 18 | rgb = map(list, zip(*colors)) 19 | 20 | # print(rgb) 21 | r = [] 22 | g = [] 23 | b = [] 24 | for row in rgb: 25 | r.append(row[0]) 26 | g.append(row[1]) 27 | b.append(row[2]) 28 | 29 | # output colors 30 | wks = op.new_sheet() 31 | wks.from_list(0, r) 32 | wks.from_list(1, g) 33 | wks.from_list(2, b) -------------------------------------------------------------------------------- /7. Miscellaneous/Loop through worksheets.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample loops through all the worksheets in the project, 3 | print out the number of rows of each sheet. 4 | ''' 5 | import originpro as op 6 | 7 | for wb in op.pages('w'): 8 | for wks in wb: 9 | print(f'Worksheet {wks.lt_range()} has {wks.rows} rows') 10 | 11 | -------------------------------------------------------------------------------- /7. Miscellaneous/Manage Project Explorer.py: -------------------------------------------------------------------------------- 1 | ''' 2 | This sample shows the management of folders under Project Explorer. It sets up same 3 | folder structure as the /Sample/Python/ and create a workbook under each sub folder. 4 | ''' 5 | import os 6 | import originpro as op 7 | 8 | # Get the path string of a folder 9 | path = os.path.join(op.path('e'), 'Samples', 'Python') 10 | 11 | # Start a new project and go to the root folder in Project Explorer 12 | op.new() 13 | op.pe.cd('/UNTITLED') 14 | 15 | # Loop over subfolders under /Samples/Python/ and create subfolders with same name. 16 | for f in os.listdir(path): 17 | fd = f'{os.path.splitext(f)[0]}' 18 | op.pe.mkdir(fd) 19 | op.pe.cd(f'"{fd}"') 20 | op.new_sheet('w',fd) 21 | op.pe.cd('/UNTITLED') 22 | 23 | 24 | -------------------------------------------------------------------------------- /7. Miscellaneous/Multi Threading.py: -------------------------------------------------------------------------------- 1 | import threading 2 | from datetime import datetime 3 | from time import sleep 4 | import originpro as op 5 | 6 | #critical section to global data 7 | def write(tt, name): 8 | global v1, v2 9 | v1.append(name) 10 | v2.append(tt) 11 | 12 | #must not do print or anything related to Origin inside the thread function 13 | def thread_task(lock, name): 14 | for _ in range(5): 15 | sleep(0.5) 16 | now = datetime.now() 17 | tt = now.strftime("%H:%M:%S.%f")[:-3] 18 | lock.acquire() 19 | write(tt, name) 20 | lock.release() 21 | 22 | #global variables to be used inside thread task 23 | v1=[] 24 | v2=[] 25 | #we need to have criticlal section for any access to shared data 26 | lock = threading.Lock() 27 | 28 | t1 = threading.Thread(target=thread_task, args=(lock,'a')) 29 | t2 = threading.Thread(target=thread_task, args=(lock,'b')) 30 | t1.start() 31 | t2.start() 32 | t1.join() 33 | t2.join() 34 | 35 | #threads done, we can put data to a worksheet 36 | wks=op.new_sheet() 37 | #need to set col(2) as time format before putting data into it 38 | wks.cols = 2 39 | wks.as_time(1, 10) 40 | 41 | wks.from_list(0, v1, 'Name') 42 | wks.from_list(1, v2, 'Time') 43 | #has to use LabTalk for setting column width 44 | wks.lt_exec("wks.col2.width=9") 45 | -------------------------------------------------------------------------------- /7. Miscellaneous/readme.md: -------------------------------------------------------------------------------- 1 | This folder contains examples related to folder management, color management in Origin with **originpro** package. 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 OriginLab Corp 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Origin Python Samples 2 | 3 | Code examples for using the **originpro** Python package to interact with Origin software. 4 | 5 | These examples will work with either the built-in Python interpreter in Origin, or via an external Python interpreter. All of the examples will work *as is* with the embedded interpreter. When using them with an external interpreter, some simple modification is required as illustrated in the [External Python Code Samples documentation](https://www.originlab.com/doc/ExternalPython/External-Python-Code-Samples). 6 | 7 | ### Running the Examples 8 | 9 | The easiest way to run these examples is to [**download this repo as a zip file**](https://github.com/originlab/Python-Samples/archive/refs/heads/main.zip). 10 | 11 | Then, simply unzip the files and open the desired file from the File menu in **Code Builder**. Then, hit **F5** to run the example. 12 | 13 | *Note that some examples require the installation of additional Python packages.* 14 | 15 | ### Documentation 16 | 17 | For embedded Python interpreter, [please click here](https://www.originlab.com/doc/python/Run-Python-in-Origin). 18 | 19 | For external Python interpreter, [please click here](https://www.originlab.com/doc/ExternalPython). 20 | 21 | For the **originpro** package documentation, [please click here](https://www.originlab.com/python/doc/originpro/annotated.html). 22 | --------------------------------------------------------------------------------