Two colormaps for same worldmap axis

5 views (last 30 days)
Tiger
Tiger on 14 Feb 2021
Edited: dpb on 15 Feb 2021
Hi,
I'm trying to attribute two datasets with the same range to two different colormaps onto one worldmap figure. I have tried every solution suggested on MathWorks, and none of them seem to work either 1) because I'm plotting onto a worldmap or 2) because the axes and ranges are the same. I saw one worldmap-specific solution, but it requires the image processing toolbox which I unfortunately don't have disc space for. Thank you in advance!

Answers (2)

dpb
dpb on 14 Feb 2021
You can only set one colormap for one graphic object with a colormap property --
colormap(target,colormap)
...
target — Target
Figure object | Axes object | PolarAxes object | GeographicAxes object | graphics object
...
You will have to create two maps overlaying to do this and then you may (will?) have problems of opacity, quite possibly.
If we had any idea at all of the effect you're trying to create, somebody could possibly add more.

Image Analyst
Image Analyst on 14 Feb 2021
Try this demo and adapt as needed:
% Make ramps so we have an image to work with.
rows = 300;
columns = 200;
values = linspace(1, 100, rows*columns);
img1 = repmat((1:rows)', [1, columns]);
% Make another one with the same range of values.
img2 = img1;
% Put both datasets into the same image.
% We need to make sure they don't share the same value range
% or else they will share the same colormap.
img = [img1, img2 + max(img1(:))];
imshow(img, []);
axis('on', 'image');
% Make colormap for the first half of the values
map1 = jet(128);
% Make colormap for the first half of the values
map2 = parula(128);
% Combine them
cmap = [map1;map2];
colormap(cmap);
colorbar;
title('Jet Color Map Parula Color Map');
Note that the left half of the image uses the jet colormap while the right half of the image uses the parula colormap.
  2 Comments
Tiger
Tiger on 14 Feb 2021
I appreciate the response
The specific issue I've run into (if it helps) is I'd like to use demcmap to color topography in the background of a worldmap, then plot points according to a different colormap on top. Any colormap I define afterwards changes the topography colormap as well. Thanks!
dpb
dpb on 14 Feb 2021
Edited: dpb on 15 Feb 2021
Again, yes, unless you have two separate graphics objects, you can have only one colormap.
Or, the trick IA uses above is to scale the second set of data so it doesn't overlap the range of the first and then the colormap is computed based on those varying ranges. That's probably doable for a map dataset but somewhat of a pain I'd think.
There really is only one colormap in the above:
>> map1 = jet(128);
% Make colormap for the first half of the values
map2 = parula(128);
% Combine them
cmap = [map1;map2];
>> whos map1 map2 cmap
Name Size Bytes Class Attributes
cmap 256x3 6144 double
map1 128x3 3072 double
map2 128x3 3072 double
>>
it's just comprised of two pieces; it's the scaling of the image data over two disparate ranges that results in the effect.
I don't have the mapping toolbox with which to play, specifically, about trying to overlay two axes.

Sign in to comment.

Categories

Find more on Colormaps in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!