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
 changing colour scale title
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

cts18488

United Kingdom
83 Posts

Posted - 11/19/2021 :  10:28:51 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

Is it possible to change colour scale title using Python?

I have tried plot.zlevels['name'] = 'test', but it didn't work.

Thank you for the help,
Tibi

Origin Ver. 2021b and Service Release SR2
Operating System: Win10Ent

YimingChen

1621 Posts

Posted - 11/19/2021 :  2:08:18 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You may need to call LabTalk script from Python to change the title. See sample code below assuming the color scale has default name SPECTRUM1:

import originpro as op
layer = op.find_graph()[0]
layer.lt_exec("SPECTRUM1.title$=newName;")


James

Edited by - YimingChen on 11/19/2021 2:08:34 PM
Go to Top of Page

cts18488

United Kingdom
83 Posts

Posted - 11/19/2021 :  3:15:30 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi James,

Thank you for your reply.

I have already imported originpro. Here is the code that I am using:

import oringinpro as op
import numpy as np

arr_x = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
wks = op.new_sheet(type='m')
wks.name = 'test'
wks.from_np(arr_x) # for matrices
x1,x2,y1,y2 = 1, 2, 1, 4
wks.xymap = x1,x2,y1,y2

gr = op.new_graph(template=op.path('e') + 'test_3map.otpu')

gl_1 = gr[0]
p1 = gl_1.add_mplot(wks, 0, type = 105)
gl_1.set_ylim(0.5, 4.5, 1)
gl_1.set_xlim(0.5, 2.5)
gl_1.rescale()

I don't know what it is the default name of the color bar, so I don't really know how to apply your example. Can you please help me showing me on my particular example?

Thank you.

PS: I have tried gl_1.lt_exec('title=test;') without success however.

quote:
Originally posted by YimingChen

You may need to call LabTalk script from Python to change the title. See sample code below assuming the color scale has default name SPECTRUM1:

import originpro as op
layer = op.find_graph()[0]
layer.lt_exec("SPECTRUM1.title$=newName;")


James

Go to Top of Page

YimingChen

1621 Posts

Posted - 11/22/2021 :  12:01:18 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Can you try the line below?
gl_1.lt_exec("SPECTRUM1.title$=test;")


To find the color scale name, you can hold on Alt key and double click on the color scale. In the popped-up dialog, find the name in Object Name which should be SPECTRUM1 by default.

Yiming

Edited by - YimingChen on 11/22/2021 12:14:56 PM
Go to Top of Page

cts18488

United Kingdom
83 Posts

Posted - 11/23/2021 :  02:24:36 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
It works. Thank you.

quote:
Originally posted by YimingChen

Can you try the line below?
gl_1.lt_exec("SPECTRUM1.title$=test;")


To find the color scale name, you can hold on Alt key and double click on the color scale. In the popped-up dialog, find the name in Object Name which should be SPECTRUM1 by default.

Yiming

Go to Top of Page

cpyang

USA
1406 Posts

Posted - 11/26/2021 :  2:18:45 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
In default templates for heatmap, the color scale title was set to

"%(?R,@LM)"

Which means to use the plot's matrix Z long name. So a better way is to just set the matrix long name (which is Z) without having to set the color scale object itself with LT code. The full code below:

import originpro as op
import numpy as np

arr = np.array([[1, -8], [3, -4], [5, 4], [7, 8]])
mat = op.new_sheet(type='m')
mat.from_np(arr)
#set the 1st matrix's long name, which is the Z lable, which the color scale will use as title
mat.set_label(0, 'Z Levels')
x1,x2,y1,y2 = 0.5, 2.5, 0.5, 4.5
mat.xymap = x1,x2,y1,y2
gr = op.new_graph(template='Heat_Map.otpu')
g = gr[0]
p = g.add_mplot(mat, 0, type = 105)
#heatmap is showing data point at the center, so need to adjust for half step size
hs = 0.5 * (x2-x1)/2;
g.set_ylim(y1-hs, y2+hs, 1)
g.set_xlim(x1-hs, x2+hs, 1)
#set plot colormap
z = p.zlevels
z['minors'] = 15
z['levels'] = [-8, 0, 8]
p.zlevels = z
p.colormap = 'BlueYellow.pal'


Also updated to
https://github.com/originlab/Python-Samples/blob/main/4.%20Graphing/Plot%20Heatmap%20from%20Matrix%20Data.py

CP

Go to Top of Page

cts18488

United Kingdom
83 Posts

Posted - 11/29/2021 :  07:15:43 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you!

quote:
Originally posted by cpyang

In default templates for heatmap, the color scale title was set to

"%(?R,@LM)"

Which means to use the plot's matrix Z long name. So a better way is to just set the matrix long name (which is Z) without having to set the color scale object itself with LT code. The full code below:

import originpro as op
import numpy as np

arr = np.array([[1, -8], [3, -4], [5, 4], [7, 8]])
mat = op.new_sheet(type='m')
mat.from_np(arr)
#set the 1st matrix's long name, which is the Z lable, which the color scale will use as title
mat.set_label(0, 'Z Levels')
x1,x2,y1,y2 = 0.5, 2.5, 0.5, 4.5
mat.xymap = x1,x2,y1,y2
gr = op.new_graph(template='Heat_Map.otpu')
g = gr[0]
p = g.add_mplot(mat, 0, type = 105)
#heatmap is showing data point at the center, so need to adjust for half step size
hs = 0.5 * (x2-x1)/2;
g.set_ylim(y1-hs, y2+hs, 1)
g.set_xlim(x1-hs, x2+hs, 1)
#set plot colormap
z = p.zlevels
z['minors'] = 15
z['levels'] = [-8, 0, 8]
p.zlevels = z
p.colormap = 'BlueYellow.pal'


Also updated to
https://github.com/originlab/Python-Samples/blob/main/4.%20Graphing/Plot%20Heatmap%20from%20Matrix%20Data.py

CP



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