matlab代码——画全球图并添加海岸线与颜色条

it2025-08-22  4

要点 

 imagesc画彩色影像图imagesc去除背景添加全球海岸线使用view镜像垂直翻转图像添加colorbar颜色条,并设置长宽,位置调整坐标轴刻度,标签,字体,大小输出为tiff格式(设置尺寸,比例,单位:cm)

代码如下:自用备份

%% 画图(全球逐项元相关图) load('G:\DATA\5MOD12Q1_UMD\out_matlab\LC_05_50.mat') figure(1) X = [-180 180]; Y = [90 -90]; f = imagesc(X,Y,LC_05);                    % imagesc函数出彩图 set(f,'alphadata',~isnan(LC_05));         % 将图像中nan数值变成白色 title('LC_05_threshold_50') % colormap(jet) colorbar('position',[0.95 0.05 0.015 0.9],'TickLength',0.02) set(gcf,'unit','centimeters','position',[0 0 20 10]);            % 设置图层 set(gca,'FontName','Times New Roman','FontSize',8,'LineWidth',1,'position',[0.03 0.05 0.9 0.9]);     % 设置坐标轴

% 画海岸线 hold on  load coast;                                                            % 加载matlab自带海岸线文件 plot(long,lat,'k-','LineWidth',0.5);                                  % 绘制海岸线,并调整颜色,线类型,线宽 axis([-180 180 -90 90])                                               % 调整坐标轴范围[xmin,xmax,ymin,ymax] set(gca,'xtick',-150:50:150)                                           % 设置x坐标轴上的刻度数据点位置 set(gca,'ytick',-60:30:60)                                             % 设置y坐标轴上的刻度数据点位置 X_lab = {'-150°' '-100°' '-50°'  '0°' '50°' '100°' '150°'};     % 自定义x轴标签 Y_lab = {'-60°' '-30°' '0°' '30°' '60°'};                       % 自定义y轴标签 set(gca,'XTickLabel',X_lab,'fontname','Time New Romans','fontsize',8)                                            % 显示x轴标签 set(gca,'YTickLabel',Y_lab,'fontname','Time New Romans','fontsize',8)                                            % 显示y轴标签 grid on                                                                 % 打开格网 box on                                                                  % 显示次坐标轴 hold off view(0,-90);                                                            % 垂直镜像90度 print('-dtiff','-r600','G:\DATA\5MOD12Q1_UMD\out_matlab\LC_05_threshold_50.tiff');  

最新回复(0)