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
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Python
 problem with change in plot style using template
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

pavi-chem

United Kingdom
26 Posts

Posted - 05/29/2023 :  3:32:09 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi Origin community,

i am trying to use a python program to batch process my FTIR spectra data using an origin graph template, the problem i am facing is the style of the plot is changed when it applying the data to my template. i am unsure why this happens, the lines are thicker width in the 3d waterfall plot. so, any advice on how to apply the template style to the plot would be great.

My code:
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)
template_plot = gr2[0].plots[col-1] # Get the corresponding plot in the template
plot.style.copy_from(template_plot.style) # Copy the plot style from the template plot


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.

YimingChen

1618 Posts

Posted - 05/30/2023 :  11:21:50 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
I couldn't reproduce the issue that the line width is different. Could you please try the sample code below? I used the system 3D waterfall graph template. Maybe you were using a customized graph template which caused the issue. Thank you.

James


import os
import originpro as op

# Import the data file
wks = op.new_sheet()
wks.from_file(os.path.join(op.path('e'), 'Samples', 'Curve Fitting', 'Linear Fit.dat'))

# Create a graph page
graph = op.new_graph(template='glWater3D')
gl=graph[0]

for col in range(1, 4):
    plot = gl.add_plot(wks, col, 0)

    
gl.group()
gl.rescale()
Go to Top of Page

pavi-chem

United Kingdom
26 Posts

Posted - 06/01/2023 :  07:26:41 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi James,

Thanks for the response. I tried your code without using my custom template. one without gl.group()
and one with gl.group().

Both graphs looks same problem with thick line widths and filled in black. the graph using gl.group()
has a colour filled lines.



If I plot them manually they look fine, so i am not sure what the issue is.


Any other suggestion please?


Thanks a bunch!
Pavi.

Edited by - pavi-chem on 06/01/2023 07:30:06 AM
Go to Top of Page

YimingChen

1618 Posts

Posted - 06/01/2023 :  2:25:59 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
If you simply execute the script I provided. Does it work?

Could you send me the project file with the wrong graph plotted?

Thank you
James
Go to Top of Page

pavi-chem

United Kingdom
26 Posts

Posted - 06/01/2023 :  4:20:15 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Here is my project. https://my.originlab.com/ftp/forum_and_kbase/Images/june1-test7.opju

Thanks a bunch!
Pavi.
Go to Top of Page

YimingChen

1618 Posts

Posted - 06/01/2023 :  5:29:39 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Can you try the script below with the worksheet activated? I still couldn't reproduce your issue.


import os
import originpro as op

# Import the data file
wks = op.find_sheet()

# Create a graph page
graph = op.new_graph(template='glWater3D')
gl=graph[0]

for col in range(1, wks.cols):
    plot = gl.add_plot(wks, col, 0)

gl.rescale()


James
Go to Top of Page

pavi-chem

United Kingdom
26 Posts

Posted - 06/13/2023 :  11:42:55 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi James,

Sorry for the delay in response. I am still getting the same issue. Do you not get the issue with the project when you run it? the graph plot looks normal without the thick lines?

Thanks for any advice.

Thanks a bunch!
Pavi.
Go to Top of Page

YimingChen

1618 Posts

Posted - 06/13/2023 :  12:40:58 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Can you go to the menu Preferences->Theme Organizer... and check if you set a system theme. If so, find the theme and right-click on it to clear the system theme.

James
Go to Top of Page

pavi-chem

United Kingdom
26 Posts

Posted - 06/14/2023 :  06:21:49 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Still same problem but the plot is colourful now. I added the excel file, outpur origin file and the program to the google drive folder, could you please check what is wrong? [https://drive.google.com/drive/folders/1iTsgu27A215BDKowbooem94HnQgGe1pY?usp=drive_linkl]

Thanks a bunch!
Pavi.
Go to Top of Page

YimingChen

1618 Posts

Posted - 06/14/2023 :  08:45:45 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Could you replace the line
plot = gl.add_plot(wks2, 0, col, col+1)

by
plot = gl.add_plot(wks2, col, 0)


Thanks,

quote:
Originally posted by pavi-chem

Hi,

Still same problem but the plot is colourful now. I added the excel file, outpur origin file and the program to the google drive folder, could you please check what is wrong? [https://drive.google.com/drive/folders/1iTsgu27A215BDKowbooem94HnQgGe1pY?usp=drive_linkl]

Thanks a bunch!
Pavi.

Go to Top of Page

pavi-chem

United Kingdom
26 Posts

Posted - 06/14/2023 :  08:58:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
omg, it worked!!

Thank you soo much :)

Thanks a bunch!
Pavi.
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000