Can I use different colormap settings on same 3D plot axes?

33 views (last 30 days)
I have a 3D plot with a DEM (digital elevation model) plot that I plot using mesh() and render with the help of light()
On top of that I have various graphical elements (bullseye, text, borders) added using plot3().
Additionally I have a series of dots added using scatter3().
Is there a way to have a different colormap for the mesh() and the scatter3() plots ?
current view using the 'cool' colormap that applies to the whole figure (both the tracks in purple and the map in turquoise).
General overview of the code for the above plot:
opengl software % Hardware OpenGL rendering is unreliable for exporting images
figure('Renderer','opengl',...
'DefaultTextFontName', 'Miryad Pro', ...
'DefaultTextFontSize', 10,...
'DefaultTextHorizontalAlignment', 'right')
hold on
% >> load Xd, Yd, XYZ here <<
mesh(Xd, Yd, XYZ);
light
colormap('cool');
% >> load lines to x,y,z here <<
plot3(x,y,z,'-k')
% >> load scatter dots to x,y,z here <<
scatter3(x,y,vertiExag.*alt(filter).*0.3048,markSize,color(filter),'Marker','.')
% additional plot settings
axis equal
extra = 40e3; % some extra space around the bullseye
axis([xc-i-extra xc+i+extra yc-i-extra yc+i+extra])
set(gcf, 'Color', 'white');
axis off
% Prepare 3D view
pos = [0, 0, 1920+2, floor((1080+2)/0.8)]; % This gives a 854 x 480 mp4/gif whith the selected cropping
set(gcf, 'Position', pos);
axis vis3d
view(-7,20) % Some fiddling required!
camzoom(1.4) % Same here!
set(gca, 'LooseInset', [0,0,0,0]);
What I tried is using linkaxes for 2D plots
ax1 = axes;
mesh(ax1, Xd, Yd, XYZ);
light
colormap(ax1, 'cool');
hold(ax1, 'on');
plot3(ax1,x,y,z,'-k');
% so far so good
ax2 = axes;
scatter3(ax2,x,y,vertiExag.*alt(filter).*0.3048,markSize,color(filter),'Marker','.');
colormap(ax2, 'parula');
linkaxes([ax1, ax2]); %Link them together --> throws warning:
% Warning: linkaxes requires 2-D axes as input. Use linkprop for generic property linking
% Plot only shows data of scatter3 in 'parula' colors. Relief data is not displayed
this does not work:
2nd attempt using linkprop from:
ax1 = axes;
mesh(ax1, Xd, Yd, XYZ);
light
colormap(ax1, 'cool');
hold(ax1, 'on');
plot3(ax1,x,y,z,'-k');
% so far so good
ax2 = axes;
scatter3(ax2,x,y,vertiExag.*alt(filter).*0.3048,markSize,color(filter),'Marker','.');
colormap(ax2, 'parula');
% alternative with linkprop for 3D plots
Link = linkprop([ax1, ax2],{'CameraUpVector', 'CameraPosition', 'CameraTarget', 'XLim', 'YLim', 'ZLim'});
setappdata(gcf, 'StoreTheLink', Link);
% plot remains empty
I also tried this:
but since I use different plot types (plot3, scatter3 etc.)
All contents of the input cell array must be of the same data type.
Error in plotRTL1090_dem (line 167)
aH = cell2mat(ancestor(v,'axes'));
Could it be, that it is not possible at all?

Accepted Answer

Tim
Tim on 10 Nov 2020
You can independently define the color value of each point in scatter3, including applying a different colormap based on some value (say height). I show an example of this below. You aren't creating multiple colormaps for the axis handle, but you are mapping a colormap to the points in scatter 3. This should prevent the issue you are seeing above where you are inheriting gray values.
% Demo: separate colormaps for scatter3 and surf in this case, mesh should
% be the same
% Add peaks & light
[X,Y,Z] = peaks(55);
surf(X,Y,Z)
shading flat
light('position', [-4, -4, 4]);
set(gca, 'color', 'k');
% set colormap for current axes to gray:
colormap gray
% Add a scatter 3 using hsv...
% define scatter function
N = 1000;
xs = linspace(4, 0, N).*cos(linspace(0, 2*pi*20, N));
ys = linspace(4, 0, N).*sin(linspace(0, 2*pi*20, N));
zs = sinc(linspace(-pi, 0, N))*10 + 5;
% Make your 'colormap' based on z or whatever you want...
c_map = hsv; % pick your map
c_dat = zs; % pick the data you want to use to define color
% that is same size as xs etc.
pnt_colors = interp1(linspace(min(c_dat), max(c_dat), size(c_map, 1)),...
c_map, c_dat(:));
hold on;
scatter3(xs, ys, zs, 50, pnt_colors, 'marker', '.');
hold off;
I get the following with this:

More Answers (1)

Simon Burkhardt
Simon Burkhardt on 10 Nov 2020
This is what I want to achieve eventually.
Done using a custom colormap, which is not ideal because the tracks also inherit the grey color from the mountains.

Categories

Find more on Colormaps in Help Center and File Exchange

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!