MATLAB Answers


saving edited colormap data

Asked by Natan
on 9 Jul 2015
Latest activity Edited by Walter Roberson
on 6 Jun 2018
After editing an existing colormap with the colormapeditor, I want to save it. The documentation states that I should do something like:
mycmap = get(fig,'Colormap');
However, the saved colormap, mycmap, has the original colormap data not the eddited one. Here's a minimal example:
Now go into the figure's gui colormap editor using >Edit>Colormap and only change yellow to blue. Now after that press Apply see that indeed the figure has changed. Now write on the command line:
mycmap = get(gcf,'Colormap')
mycmap =
0.5000 0 0
1.0000 0 0
1.0000 0.5000 0
1.0000 1.0000 0
1.0000 1.0000 0.5000
1.0000 1.0000 1.0000
there no "blue" ([0 0 1]) color. Interestingly, when the figure is saved the colormap is saved with it, but for some reason I cant access the edited colormap. What am I doing wrong? (I'm using Matlab 2014b)


Sign in to comment.


3 Answers

Answer by Natan
on 12 Oct 2015
 Accepted Answer

It looks like the colormap is now associated with the axes rather than the figure. So,
cmap = colormap(gca);
will retrieve the edited map.


So I provided the correct solution but don't even get a vote? :(
on 28 Dec 2015
saying "So use gca" is a very partial answer. I had to go and investigate how one should use gca, and that was far from the regular way gca is usually used (i.e. set(gca...) ). that is why I felt I had to write the full answer.
Very useful! I have met the same problem and maybe it's a bug. It's strange that the colormaps of gca and gcf are different.

Sign in to comment.

Answer by Walter Roberson
on 10 Oct 2015

Starting in R2014b, colormaps are per-axes rather than per-figure. So use gca (or some other way of identifying the axes) instead of gcf .


mycbar= get(gca,Colormap'); % this works
set(gcf,'Colormap',mycbar); %this works
set(gca) does not work in R2017a. This does not sound right and is confusing.
set(gca, 'Colormap', mycbar)

Sign in to comment.

Answer by Sean de Wolski
on 9 Jul 2015

Is gcf, the same as fig?


on 9 Jul 2015
well, that's not surprising. I just hope other people would still look at this question, even though there seems to be an "answer" though it is still not answered.
on 10 Oct 2015
I have the same problem! This is a bug that needs fixing, or a good explaination
on 12 Oct 2015
I found the answer, see below...

Sign in to comment.