matlab如何给海洋添加纯色的底色像python那样
偶尔看到有人需求这个,
因为他觉得在世界地图上直接画数据,太单调:
例如:
想给海洋添加底色浅蓝色或者其他都可以改:
例如python就有底图:为此,咱也可以拿他的颜色使用;
颜色提取可以见以前的文章:
更改之后的图片如下:
什么颜色都可以的!
首先数据构造,你们可以使用自己的真实数据:
clear;clc;close all;
% 海洋数据构造;
lon = 0:360;
lat = -90:90;
[x,y]=meshgrid(lon,lat);
x = x';y=y';
depth = ones(length(lon),(length(lat)));
%
lon_scatter=fix(min(lon)+(max(lon)-min(lon))*rand(100,1));
lat_scatter=fix(min(lat)+(max(lat)-min(lat))*rand(100,1));
size_scatter = fix(1+(10)*rand(100,1));
第二步骤:选取颜色:
画图 python 世界底图颜色提取,
参考以往方案
https://mp.weixin.qq.com/s?__biz=MzkxMDAxNjE4MA==&mid=2247497499&idx=1&sn=ca993ec62754cd89d1f136eeee0a25c3&chksm=c1335cc0f644d5d6c06ebad4313f04c6b8850b0f555bc555d5ef0df7302c2b7558d970537a08&token=1329178493&lang=zh_CN#rd
colors1 = [ 240 255 255]./255;
colors2 = [ 121 172 207]./255;
第三步画图
close all
figure
set(gcf,'position',[50 50 1250 850],'color','w')
m_proj('Robinson','lon',[0 360],'lat',[-90 90])
% m_contourf(x,y,depth,'linestyle','none')
m_pcolor(x,y,depth);
shading flat
colormap(colors1) ;
m_coast('patch',[0.9 0.9 0.9],'edgecolor','k');
m_grid('box','fancy','linestyle','none');
hold on
m_scatter(lon_scatter,lat_scatter,20*size_scatter,size_scatter,'MarkerEdgeColor',[0 .8 .3],...
'MarkerFaceColor',[0 .8 .3],...
'LineWidth',1.5)
export_fig('给海洋添加底图.jpg','-r600')
全部代码:
clear;clc;close all;
% 海洋数据构造;
lon = 0:360;
lat = -90:90;
[x,y]=meshgrid(lon,lat);
x = x';y=y';
depth = ones(length(lon),(length(lat)));
%
lon_scatter=fix(min(lon)+(max(lon)-min(lon))*rand(100,1));
lat_scatter=fix(min(lat)+(max(lat)-min(lat))*rand(100,1));
size_scatter = fix(1+(10)*rand(100,1));
% 画图 python 世界底图颜色提取,
% 参考以往方案
% https://mp.weixin.qq.com/s?__biz=MzkxMDAxNjE4MA==&mid=2247497499&idx=1&sn=ca993ec62754cd89d1f136eeee0a25c3&chksm=c1335cc0f644d5d6c06ebad4313f04c6b8850b0f555bc555d5ef0df7302c2b7558d970537a08&token=1329178493&lang=zh_CN#rd
%
colors1 = [ 240 255 255]./255;
colors2 = [ 121 172 207]./255;
close all
figure
set(gcf,'position',[50 50 1250 850],'color','w')
m_proj('Robinson','lon',[0 360],'lat',[-90 90])
% m_contourf(x,y,depth,'linestyle','none')
m_pcolor(x,y,depth);
shading flat
colormap(colors1) ;
m_coast('patch',[0.9 0.9 0.9],'edgecolor','k');
m_grid('box','fancy','linestyle','none');
hold on
m_scatter(lon_scatter,lat_scatter,20*size_scatter,size_scatter,'MarkerEdgeColor',[0 .8 .3],...
'MarkerFaceColor',[0 .8 .3],...
'LineWidth',1.5)
export_fig('给海洋添加底图.jpg','-r600')
close all
figure
set(gcf,'position',[50 50 1250 850],'color','w')
m_proj('Robinson','lon',[0 360],'lat',[-90 90])
% m_contourf(x,y,depth,'linestyle','none')
m_coast('patch',[0.9 0.9 0.9],'edgecolor','k');
m_grid('box','fancy','linestyle','none');
hold on
m_scatter(lon_scatter,lat_scatter,20*size_scatter,size_scatter,'MarkerEdgeColor',[0 .8 .3],...
'MarkerFaceColor',[0 .8 .3],...
'LineWidth',1.5)
export_fig('未给海洋添加底图.jpg','-r600')