【matlab程序】双x坐标轴_解决问题,给出问题并解决
问题:
解决方案一:
解决方案二:
程序汇总:
% double x-axis
clear;clc;close all;
load('sst_wind.mat')
cmap = load('colormore_41.txt');
% 问题:如下
close all
figure
set(gcf,'position',[50 40 1200 900],'color','w')
subplot(211)
plot(wind,lat,'r')
ylim([min(lat(:)) max(lat(:))])
title('问题:lat是一样的,如何放在一张图中,给出两种解决方案')
subplot(212)
pcolor(lon,lat,sst)
shading interp
% colorbar
colormap(cmap)
title('问题:lat是一样的,如何放在一张图中,给出两种解决方案')
export_fig('问题.jpg','-r600')
% %方法一 放大法
close all
figure
set(gcf,'position',[50 40 1200 900],'color','w')
pcolor(lon,lat,sst)
shading interp
% colorbar
colormap(cmap)
hold on
plot(min(lon(:))+20+15*wind,lat(1,:),'linewidth',2,'color','r');% 按照x轴放大数据;
title('方法一 放大法')
xlim([min(lon(:)) max(lon(:))])
ylim([min(lat(:)) max(lat(:))])
box on
set(gca, 'Color','none', 'xcolor','k','ycolor','k','fontsize',12,'fontname','time news roman','fontweight','bold','linewidth',2);
export_fig('方法一_放大法.jpg','-r600')
% 方法二 双x轴法
close all
figure
set(gcf,'position',[50 40 1200 900],'color','w')
pcolor(lon,lat,sst)
shading interp
% hb = colorbar;
% set(hb,'position',[0.95 0.1100 0.0213 0.8150])
colormap(cmap)
xlim([min(lon(:)) max(lon(:))])
ylim([min(lat(:)) max(lat(:))])
xlabel('Lon','fontsize',12,'fontname','time news roman','fontweight','bold')
ylabel('Lat','fontsize',12,'fontname','time news roman','fontweight','bold')
set(gca, 'Color','none', 'xcolor','k','ycolor','k','fontsize',12,'fontname','time news roman','fontweight','bold','linewidth',1.5);
ax1 = gca;
ax2 = axes('Position',get(ax1,'Position'),'XAxisLocation','top', 'YAxisLocation','right', 'Color','none', 'xcolor','k','ycolor','k');
h2 = plot(wind,lat(1,:),'Color','r','linewidth',2,'Parent',ax2);
set(gca,'color','none','XAxisLocation','top', 'YAxisLocation','right', 'Color','none', 'xcolor','k','ycolor','k','fontsize',12,'fontname','time news roman','fontweight','bold','linewidth',1.5);
ylim([min(lat(:)) max(lat(:))])
xlim([-1 1])
xlabel('Wind speed (m/s)','fontsize',12,'fontname','time news roman','fontweight','bold')
export_fig('方法二_双x轴坐标.jpg','-r600')
以下没用:
% double x-axis
clear;clc;close all;
load('sst_wind.mat')
cmap = load('colormore_41.txt');
% 问题:如下
close all
figure
set(gcf,'position',[50 40 1200 900],'color','w')
subplot(211)
plot(wind,lat,'r')
ylim([min(lat(:)) max(lat(:))])
title('问题:lat是一样的,如何放在一张图中,给出两种解决方案')
subplot(212)
pcolor(lon,lat,sst)
shading interp
% colorbar
colormap(cmap)
title('问题:lat是一样的,如何放在一张图中,给出两种解决方案')
export_fig('问题.jpg','-r600')
% %方法一 放大法
close all
figure
set(gcf,'position',[50 40 1200 900],'color','w')
pcolor(lon,lat,sst)
shading interp
% colorbar
colormap(cmap)
hold on
plot(min(lon(:))+20+15*wind,lat(1,:),'linewidth',2,'color','r');% 按照x轴放大数据;
title('方法一 放大法')
xlim([min(lon(:)) max(lon(:))])
ylim([min(lat(:)) max(lat(:))])
box on
set(gca, 'Color','none', 'xcolor','k','ycolor','k','fontsize',12,'fontname','time news roman','fontweight','bold','linewidth',2);
export_fig('方法一_放大法.jpg','-r600')
% 方法二 双x轴法
close all
figure
set(gcf,'position',[50 40 1200 900],'color','w')
pcolor(lon,lat,sst)
shading interp
% hb = colorbar;
% set(hb,'position',[0.95 0.1100 0.0213 0.8150])
colormap(cmap)
xlim([min(lon(:)) max(lon(:))])
ylim([min(lat(:)) max(lat(:))])
xlabel('Lon','fontsize',12,'fontname','time news roman','fontweight','bold')
ylabel('Lat','fontsize',12,'fontname','time news roman','fontweight','bold')
set(gca, 'Color','none', 'xcolor','k','ycolor','k','fontsize',12,'fontname','time news roman','fontweight','bold','linewidth',1.5);
ax1 = gca;
ax2 = axes('Position',get(ax1,'Position'),'XAxisLocation','top', 'YAxisLocation','right', 'Color','none', 'xcolor','k','ycolor','k');
h2 = plot(wind,lat(1,:),'Color','r','linewidth',2,'Parent',ax2);
set(gca,'color','none','XAxisLocation','top', 'YAxisLocation','right', 'Color','none', 'xcolor','k','ycolor','k','fontsize',12,'fontname','time news roman','fontweight','bold','linewidth',1.5);
ylim([min(lat(:)) max(lat(:))])
xlim([-1 1])
xlabel('Wind speed (m/s)','fontsize',12,'fontname','time news roman','fontweight','bold')
export_fig('方法二_双x轴坐标.jpg','-r600')