T O P I C R E V I E W |
cts18488 |
Posted - 11/19/2021 : 10:28:51 AM 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
|
6 L A T E S T R E P L I E S (Newest First) |
cts18488 |
Posted - 11/29/2021 : 07:15:43 AM 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
|
cpyang |
Posted - 11/26/2021 : 2:18:45 PM 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
|
cts18488 |
Posted - 11/23/2021 : 02:24:36 AM 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
|
YimingChen |
Posted - 11/22/2021 : 12:01:18 PM 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 |
cts18488 |
Posted - 11/19/2021 : 3:15:30 PM 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
|
YimingChen |
Posted - 11/19/2021 : 2:08:18 PM 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 |
|
|