The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
 All Forums
 Origin Forum for Programming
 Forum for Python
 Error while using originpro to plot 3D waterfall

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
pavi-chem Posted - 05/24/2023 : 08:20:36 AM
Origin Ver. and Service Release (Select Help-->About Origin): OriginPro 2022b (64-bit) SR1
9.9.5.171 (Academic)
Operating System: Windows 10 enterprise ,64-bit operating system, x64-based processor.

Hello Origin community,

I hope you are doing well. I'm currently working on a this program to automate my data processing and that involves using the originpro library to create graphs in OriginPro software based on template files and data files. However, I've encountered an error while trying to use 3d waterfall template to plot a series of FTIR spectra and would greatly appreciate your assistance in identifying and resolving the issue.

The problem arises when I attempt to use the add_plot() method for creating a plot in the second graph. I receive the following error message:
Traceback (most recent call last):
File "C:\Users\r01pg22\AppData\Roaming\JetBrains\PyCharmCE2023.1\scratches\scratch.py", line 60, in <module>
gr[0].add_plot(wks, x_col=1, y_col=list(range(12)), type=62)
TypeError: GLayer.add_plot() got an unexpected keyword argument 'x_col'

Based on this error message, it appears that the add_plot() method does not recognize the x_col argument I'm passing to it. Consequently, the graph creation process fails.

To provide some context, here is a snippet of the relevant code:
# Prompt user to select an Origin template file for graph 2
template_file_path = filedialog.askopenfilename(title="Select Origin Template File for Graph 2", filetypes=[("Origin Template Files", "*.otpu")])

# Prompt user to select an Excel file for the selected template for graph 2
excel_file_path = filedialog.askopenfilename(title=f"Select Excel File for {os.path.basename(template_file_path)}", filetypes=[("Excel Files", "*.xlsx")])

# Create a new worksheet
wks = op.new_sheet()

# Load the Excel file into Origin worksheet for graph 2
wks.from_file(excel_file_path, True) # Set the second parameter to True to specify that the first row contains column names

# Create a new graph using the selected template
gr = op.new_graph(template=template_file_path)

# Add plot to the graph using the data from the worksheet for graph 2
gr[0].add_plot(wks, x_col=1, y_col=list(range(12)), type=62)
gr[0].rescale()

Any insights, suggestions, or solutions you can provide would be highly appreciated. Thank you in advance for your time and assistance. Please let me know if you require any additional information.

Best regards,
Pavi

PAVI
2   L A T E S T    R E P L I E S    (Newest First)
pavi-chem Posted - 05/26/2023 : 11:38:06 AM
Hi,

Thank you, it worked.
But my graph looks different from the template i used, the width of the line is thick instead of thin and the base plane is set to none where as mine is set to minimum and filled with white colour. I assumed that it would apply the plot setting of the template but somehow it changed. is there a way I can apply the same theme or edit the properties of the plot?

import originpro as op
import os
import tkinter as tk
from tkinter import filedialog

# Very useful, especially during development, when you are
# liable to have a few uncaught exceptions.
# Ensures that the Origin instance gets shut down properly.
# Note: only applicable to external Python.
import sys


def origin_shutdown_exception_hook(exctype, value, traceback):
"""Ensures Origin gets shut down if an uncaught exception"""
op.exit()
sys.__excepthook__(exctype, value, traceback)


sys.excepthook = origin_shutdown_exception_hook

# Only run if external Python
if op.oext:
op.set_show(True)

# Prompt user to select an Origin template file for graph 2
root = tk.Tk()
root.withdraw()
template_file_path2 = filedialog.askopenfilename(title="Select Origin Template File for Graph 2", filetypes=[("Origin Template Files", "*.otpu")])

# Prompt user to select an XLSX file for the second graph
xlsx_file_path = filedialog.askopenfilename(title=f"Select XLSX File for {os.path.basename(template_file_path2)}", filetypes=[("XLSX Files", "*.xlsx")])

# Load the XLSX file into a new worksheet
wks2 = op.new_sheet()
wks2.from_file(xlsx_file_path, False)

# Create a new graph using the selected template for graph 2
gr2 = op.new_graph(template=template_file_path2)

# Define the range of columns (1-12) for the y-axis
y_columns = list(range(1, 13)) # Adjust the range as needed

for col in range(1, 13): # Adjust the range as needed
plot = gr2[0].add_plot(wks2, 0, col, col+1)


gr2[0].rescale()


# Tile all windows
op.lt_exec('win-s T')

# Prompt user for the output Origin file name
root = tk.Tk()
root.withdraw()
output_file_path = filedialog.asksaveasfilename(title="Save Output Origin File", filetypes=[("Origin Project Files", "*.opju")])

# Save the project to the specified output file path using both op.oext and op.save
if op.oext:
op.save(os.path.abspath(output_file_path))
else:
gr.save(os.path.abspath(output_file_path))
gr2.save(os.path.abspath(output_file_path))


Thanks a bunch!
Pavi.
ChaoC Posted - 05/24/2023 : 2:45:06 PM
Hello Pavi,

The keyword is colx instead of x_col.

See: https://docs.originlab.com/originpro/classoriginpro_1_1graph_1_1GLayer.html#a9d5148e776444f3723ee126d1781b151

Best,
Chao

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000