T O P I C R E V I E W |
Joyserver |
Posted - 06/28/2021 : 11:24:09 AM 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. |
3 L A T E S T R E P L I E S (Newest First) |
YimingChen |
Posted - 07/01/2021 : 09:27:38 AM 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 |
Joyserver |
Posted - 06/30/2021 : 09:29:33 AM 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
|
YimingChen |
Posted - 06/29/2021 : 11:13:53 AM Can you provide the script to show the issue? Especially how you update the worksheet. Thank you.
James |
|
|