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
 Binding plots to column names
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Joyserver

Austria
5 Posts

Posted - 06/28/2021 :  11:24:09 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Ver. and Service Release (Select Help-->About Origin): Origin pro 2021
Operating System: Windows 10

Hi,

I am using python code to update a worksheet in Originpro. A graph is made based on some columns in this worksheet. When the number of columns changes, I have found that the graph is not bound to the columns that I want.

For instance, with the first update, there are two columns "width" and "area" (long name in the worksheet). I use column "width" and "area" to draw a scatter plot on the graph and would like the plot to bind with those two columns.

However, with the second update, I receive 3 columns, e.g., "width", "length", "area". Then the scatter plot is not any more based on the column "width" and "area" because the new column "length" disrupts the original order of those two columns. I am wondering whether it is possible to bind plots to columns names, so that, no matter how the columns change in the worksheet, the plot is always made with the assigned column names?

Thanks in advance for your support.

YimingChen

1618 Posts

Posted - 06/29/2021 :  11:13:53 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Can you provide the script to show the issue? Especially how you update the worksheet. Thank you.

James
Go to Top of Page

Joyserver

Austria
5 Posts

Posted - 06/30/2021 :  09:29:33 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi, James

Please test the following script. example.opju contains a 'BTest' worksheet, in which there are orginally two columns: width and area. I plotted area vs width in a graph 'GTest'. After updating the worksheet 'BTest' with this script, the plot changed to 'length vs width'. However, I still want to keep the original plot of 'area vs width'.

Note that strOriginProject needs to be changed with reference to the opju file on your computer.

import originpro as op
import pandas as pd
strOriginProject='\example.opju'
op.open(strOriginProject)
df_test=pd.DataFrame([[1,2,3],[3,4,5],[7,8,9]],
columns=['width','length','area'])


wb=op.find_book('w','BTest')
ws=wb[0]
ws.clear()

ncol=len(df_test.columns)
ws.cols=ncol
print(ws.cols)
ws.from_df(df_test)
op.save()



quote:
Originally posted by YimingChen

Can you provide the script to show the issue? Especially how you update the worksheet. Thank you.

James

Go to Top of Page

YimingChen

1618 Posts

Posted - 07/01/2021 :  09:27:38 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
After you set the column number to 3 by ws.cols=ncol, you need to move the area column to the right by adding a line:
ws.move_cols(1, 1, 1)

The plot on the graph is linked to the column by the internal id of the column instead of the column longname. Hope it is clear.

James

Edited by - YimingChen on 07/01/2021 09:28:18 AM
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