Using two colormaps on the same image (no subplots)
38 次查看(过去 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 个评论
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 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Colormaps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!