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
 LabTalk Forum
 How can I print out the colormap used?
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

mtav

4 Posts

Posted - 05/28/2020 :  5:22:22 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

I want to print out the colormap used in a surface plot, so I can reuse exactly the same in other plotting programs.

How can I do this, aside from manually copying over every range and color value from the Plot details->colormap dialog (where I cannot actually even access the color value)?

Or is there a way to make sense of the exported XML .oth colormap?

It doesn't have to be in LabTalk, but that seems to have worked better than the python module so far.
I am happy with any solution for this.

Infos:
------
Origin Ver. and Service Release (Select Help-->About Origin):
Origin 2019b (64-bit)
9.6.5.169 (Academic)
Operating System: Windows 10

cpyang

USA
1406 Posts

Posted - 05/28/2020 :  7:50:24 PM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can save it to an XML file, like

string str1="%Ytest.xml";
layer.cmap.save(str1$);


and to apply

string str1="%Ytest.xml";
layer.cmap.load(str1$);


See

https://www.originlab.com/doc/LabTalk/ref/Layer-CMap-obj

CP
Go to Top of Page

mtav

4 Posts

Posted - 05/29/2020 :  05:19:04 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Mmh, but that is the same as exporting/saving the colormap via the GUI.
I could not find an easy way to read the values from the XML file.
Converting the base64 entries just gave me some other cryptic text (or binary?).
Is the colormap XML format documented anywhere?

I want the levels and RGB values in a format I can use in Matlab, python, pgfplot, etc, i.e. I want it in a text format for example.

I noticed I can get the colors in the "origin internal color code" via:
layer.cmap.colorN

And find out what the "origin internal color code" is via the color() function.

Is there a function converting the internal code to RGB or hex?

Now I just somehow need to combine these things with a loop to print out a list of RGB values, but I am not familiar enough with LabTalk yet.
Go to Top of Page

lkb0221

China
497 Posts

Posted - 05/29/2020 :  10:18:14 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Try this:
https://www.originlab.com/doc/LabTalk/ref/ocolor2rgb-func
Go to Top of Page

mtav

4 Posts

Posted - 06/01/2020 :  08:51:46 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks. That is very useful!

Would you happen to know how to use numbers to generate a string to call the appropriate function/macro?

i.e. how can I do something like this:
loop (num, 0, 60)
      {
         OCOLOR = $("layer.cmap.color" + $(num)); // should call layer.cmap.color0 to layer.cmap.color60
         RGB = ocolor2rgb(OCOLOR);
         type "$(num); $(OCOLOR); $(RGB)";
      }




Edited by - mtav on 06/01/2020 08:52:41 AM
Go to Top of Page

lkb0221

China
497 Posts

Posted - 06/01/2020 :  09:52:54 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
You can directly use:

loop (num, 0, 60) {
    int OCOLOR = layer.cmap.color$(num);
    int RGB = ocolor2rgb(OCOLOR);
    type "$(num); $(OCOLOR); $(RGB)";
}

Edited by - lkb0221 on 06/01/2020 09:54:12 AM
Go to Top of Page

mtav

4 Posts

Posted - 06/01/2020 :  11:32:20 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks a lot. I solved my problem now.

Origin LabTalk script to save the colormap to a CSV file:
type -gbe "origin_colormap.csv";
loop (num, 0, layer.cmap.numColors) {
    int OCOLOR = layer.cmap.color$(num);
    int RGB = ocolor2rgb(OCOLOR);
    type "$(num); $(OCOLOR); $(RGB)";
}
type -ge;

The CSV file will be saved in the current project folder (Help->Open folder->Current project).

Matlab script to load the colormap:
m = load('origin_colormap.csv');
val = m(:,3);
B = fix(val./65536);
G = fix(mod(val, 65536)./256);
R = fix(mod(val, 256));
map255 = [R,G,B];
mapNormalized = map255./255;
colormap(mapNormalized);




Things left to do, but that I do not need right now:
-export and use level values (I did it manually. They were linear, so easy.)
-add below/above levels
-make it easy to use

Edited by - mtav on 06/01/2020 11:33:21 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