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 matrix dimensions and z-scale for plottin
 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/17/2021 :  1:28:51 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

I am using the following code to generate a heatmap, however it is either the colour or the axes that are off. This is the code that I am using.

arr_x = np.array([[1, 2], [3, 4], [5, 6], [7, 8]])
wks = op.new_sheet(type='m')
wks.from_np(arr_x)
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)

If I am using this, the x and y axes are correct, however the heatmap and the scale is not correct.
If instead of gl_1.set_xlim/ylim I am using gl_1.rescale(), the heatmap and scale are correct. Is this a way to fix this?

I am attaching few images as a proof, and a way how I can change this in Origin - if it is possible to do the same from Python straight?

Also, is there a user-manual, where it describes what each function do and how to use it with all the options? (for Python)

Thank you,
Tibi

PS: Please let me know if something is unclear.

Origin Ver.2021b and Service Release SR2
Operating System: Win 10 Ent


Edited by - cts18488 on 11/17/2021 1:31:23 PM

cpyang

USA
1406 Posts

Posted - 11/17/2021 :  4:35:10 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Here

import originpro 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.from_np(arr_x)
x1,x2,y1,y2 = 0.5, 2.5, 0.5, 4.5
wks.xymap = x1,x2,y1,y2
gr = op.new_graph(template='Heat_Map.otpu')
gl_1 = gr[0]
plot = gl_1.add_mplot(wks, 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;
gl_1.set_ylim(y1-hs, y2+hs, 1)
gl_1.set_xlim(x1-hs, x2+hs, 1)
#set plot colormap
z = plot.zlevels
z['minors'] = 2
z['levels'] = [1, 3,7, 8]
plot.zlevels = z
plot.colormap = 'BlueYellow.pal'



I also put this into Originlab Github sample codes area

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/19/2021 :  10:14:36 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you. It is working so nice.

quote:
Originally posted by cpyang

Here

import originpro 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.from_np(arr_x)
x1,x2,y1,y2 = 0.5, 2.5, 0.5, 4.5
wks.xymap = x1,x2,y1,y2
gr = op.new_graph(template='Heat_Map.otpu')
gl_1 = gr[0]
plot = gl_1.add_mplot(wks, 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;
gl_1.set_ylim(y1-hs, y2+hs, 1)
gl_1.set_xlim(x1-hs, x2+hs, 1)
#set plot colormap
z = plot.zlevels
z['minors'] = 2
z['levels'] = [1, 3,7, 8]
plot.zlevels = z
plot.colormap = 'BlueYellow.pal'



I also put this into Originlab Github sample codes area

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/25/2021 :  5:15:12 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,
I have one more question: is it possible to for colourbar to specify only the minimum and the maximum and the rest to be picked up by the Origin?

I have tried z['levels'] = [-8, 8], but it didn't work as I want, the colour stayed the same of template.

I appreciate the help.

Tibi
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 11/25/2021 :  9:52:28 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Looks like there is a bug there, if you have at least one intermediate level, then it works, like [-8,0,8]

We can fix this next version.

CP
Go to Top of Page

cts18488

United Kingdom
83 Posts

Posted - 11/26/2021 :  06:36:48 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi,

Thank you for that.

In the image attached I have shown what I want to do. The first heatmap is the one I can generate now. The one is the one using the intermediate (I am don't really like as there are not so many intermediates in the colour bar). The third one is a modification of the first one on which I have changed manually the minimum and maximum value.
If that can be achieved (the third heatmap) in the next update, that would be fantastic.

Regards,
Tibi



quote:
Originally posted by cpyang

Looks like there is a bug there, if you have at least one intermediate level, then it works, like [-8,0,8]

We can fix this next version.

CP


Go to Top of Page

cpyang

USA
1406 Posts

Posted - 11/26/2021 :  11:23:00 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Looks to me you just want more intermediate levels? Try increasing it? like


z['minors'] = 10


CP
Go to Top of Page

cpyang

USA
1406 Posts

Posted - 12/02/2021 :  11:51:13 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
We have released SR1 which fix the bug with

z['levels'] = [-8, 8]

We have replaced the 2022 installer, so just download and repair from

https://www.originlab.com/index.aspx?go=PRODUCTS%2fOrigin&pid=3292

CP
Go to Top of Page

cts18488

United Kingdom
83 Posts

Posted - 12/07/2021 :  07:54:20 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thank you!

quote:
Originally posted by cpyang

We have released SR1 which fix the bug with

z['levels'] = [-8, 8]

We have replaced the 2022 installer, so just download and repair from

https://www.originlab.com/index.aspx?go=PRODUCTS%2fOrigin&pid=3292

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