Using two colormaps on the same image (no subplots)

133 次查看(过去 30 天)
Hi there, I have this code as shown below and I am trying to plot a colormap for topography first and then plot some data as a scatter graph on top where the colours of data points represent a date.
I am trying to define both colormaps so that matlab keeps them seperate but it keeps plotting them bpth on the same colorescale (please see my code).
load('x_data.mat')
load('y_data.mat')
load('z_data.mat')
% set axis
h=[30.3 30.45 40.7 40.8];
lat_lon_proportions(h) %function taken from Jonathen Sullivan - available from https://uk.mathworks.com/matlabcentral/fileexchange/32462-correctly-proportion-a-lat-lon-plot
pcolor(X,Y,Z); %shades topography
shading interp
m.EdgeColor = 'none'; % hides edges so looks pretty
% map personalising
xlabel('Longitude (deg, E)');
ylabel('Latitude (deg, N)')
hold on
topo=demcmap([min(Z(:)) 800], 40 ) % defined elevation limits
cb=colorbar; % inserts colorbar
set(get(cb,'label'),'string','Elevation (km)');
%set axis limits
xlim([30.3 30.45])
ylim([40.7 40.8])
hold on
%read in dates
DateString = {'2012/06/11'; '2012/06/11'; '2012/06/12'; '2012/06/12'; '2012/06/12'; '2012/06/12'; '2012/06/12'; '2012/06/14'; '2012/06/15'; '2012/06/22'; '2012/07/07'; '2012/07/07'; '2012/07/07'; '2012/12/14'; '2013/04/23'};
formatIn = 'yyyy/mm/dd';
dates= datenum(DateString,formatIn);
% read in locations (initial velocity model)
Lat=[40.760973 40.757441 40.759563 40.758157 40.760622 40.754624 40.761657 40.757445 40.760271 40.759577 40.760978 40.762381 40.760268 40.757441 40.751802];
Long=[30.406552 30.390829 30.402853 30.404705 30.40794 30.387133 30.38527 30.394529 30.409328 30.421357 30.413954 30.4084 30.405627 30.390829 30.379737];
%% Plot 2D
y2= Lat;
x2= Long;
d= dates;
sz=70;
hold on
scatter(x2,y2,sz,d,'filled')
xlabel('Longitude')
ylabel('Latitude')
set(gca,'color',[64 64 64]/255,'FontSize',18)
dpoints=colormap(autumn); % shows it from red to yellow
c=colorbar('southoutside');
c.Ticks=[735040 735190 735330]
c.TickLabels={'June 2012','November 2012','April 2013'}
% define color maps
cmap = [topo;dpoints];
colormap(cmap);
Any help would be fantastic
Many thanks in advance
  3 个评论
P_L
P_L 2019-3-18
Hi Adam, Thank you for getting back to me. I have taken your advice and taken to specifying the colours for a subset of data points as show below :
My question now is that how would I get my colorbar to work? because right now it just shows the same colours as the one for the elevation
Many Thanks
L1 = (d >= 735030 ) & (d <= 735050); % Logical Subscripts For Condittion #1
L2 = (d >= 735051 ) & (d <= 735210);
L3 = (d >= 735211 ) & (d <= 735220);
L4 = (d >= 735221 );
scatter(x2(L1),y2(L1),sz,d(L1),'b','filled');hold on
scatter(x2(L2),y2(L2),sz,d(L2),'r','filled');hold on
scatter(x2(L3),y2(L3),sz,d(L3),'g','filled');hold on
scatter(x2(L4),y2(L4),sz,d(L4),'y','filled');
xlabel('Longitude')
ylabel('Latitude')
set(gca,'color',[64 64 64]/255,'FontSize',18)
c=colorbar('southoutside');
c.Ticks=[735040 735190 735330]
c.TickLabels={'June 2012','November 2012','April 2013'}
Adam
Adam 2019-3-18
You can only have one colourbar per axes (corresponding to the one colourmap per axes) so as mentioned above, mapping to rgb values for your scatter plot works so long as you don't want to see a colourbar for them (you can create your own colourbar, but that is a lot of effort!)

请先登录,再进行评论。

回答(1 个)

KSSV
KSSV 2019-3-18

类别

Help CenterFile Exchange 中查找有关 Colormaps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by