Project Folders

Export Graphs as Images from Sample Projects

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'c')+ r'\Graphing\Trellis Plots - Box Charts.opju')


# export graph to an image
if gg:

import os
if len(f):

Extract Image Colors

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:

# output colors
wks = op.new_sheet()
wks.from_list(0, r)
wks.from_list(1, g)
wks.from_list(2, b)

Manage Project Explorer

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'/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]}''"{fd}"')