chaoshu的个人博客分享 http://blog.sciencenet.cn/u/chaoshu

博文

分享:MATLAB创建包含多个 x 轴和 y 轴的图

已有 3219 次阅读 2022-5-3 20:42 |个人分类:matlab|系统分类:科研笔记

figure;


set(gcf,'Position',[80 80 1000 700]) %设置图片整体大小,四个参数分别为xmin,ymin,width,height

ha = tight_subplot(1,1,[.08 .03],[.05 .05],[.03 .03]);

axes(ha(1));

%line([1,2],[3,4])将画出(1,3)到(2,4)的一条直线

plot([2023 2023],[0,380],'r-');

s=0;

for i=6:6:372

    hold on

    plot([2011 2035],[i,i],'--','color',[0.5 0.5 0.5]);

    s=s+1;

    hold on

    scatter(ts.timeseries(s).time+1,ts.timeseries(s).u*100+i,'.','g');

    hold on

    text('String',ts.timeseries(s).site.name,'Position',[2010.3 i],'FontSize',5);

    s=s+1;

    hold on

    scatter(ts.timeseries(s).time+13,ts.timeseries(s).u*100+i,'.','g');

    hold on

    text('String',ts.timeseries(s).site.name,'Position',[2035.1 i],'FontSize',5);

end


set(gca,'XLim',[2010 2036]);%X轴的数据显示范围

set(gca, 'xTick', 2010:2:2036);%设置刻度线

set(gca,'XTickLabel',{'2010','2012','2014','2016','2018','2020','2022', ...

    '2010','2012','2014','2016','2018','2020','2022', },'FontSize',8);%设置刻度线下面显示数字

set(gca,'YLim',[0 380]);%X轴的数据显示范围

set(gca, 'yTick', 0:30:380);%设置刻度线

%set(gca,'XTickLabel',{'2010','2012','2014','2016','2018','2020','2022', ...

%    '2010','2012','2014','2016','2018','2020','2022', },'FontSize',8);%设置刻度线下面显示数字


ax1 = gca; % current axes

hold on

%上侧、右侧坐标轴显示方法

%'Color','none'参数很关键,不然会遮盖之前绘制的图形

ax2 = axes('Position',get(ax1,'Position'),'xAxisLocation','top','yAxisLocation','right','Color','none','XColor','k','YColor','k');

set(gca,'XLim',[2009 2036]);%X轴的数据显示范围

set(gca, 'xTick', 2010:2:2036);%设置刻度线

set(gca,'XTickLabel',{'2010','2012','2014','2016','2018','2020','2022', ...

    '2010','2012','2014','2016','2018','2020','2022', },'FontSize',8);%设置刻度线下面显示数字

set(gca,'YLim',[0 380]);%X轴的数据显示范围

set(gca, 'yTick', 0:30:380);%设置刻度线


6de5fe5bdb59ac43337938f46ef0141.png



https://wap.sciencenet.cn/blog-858128-1336853.html

上一篇:推荐:特别好用的Matlab设置子图边界范围
下一篇:质量变化(气体、地表水、冰川...)计量单位
收藏 IP: 103.170.26.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-4-20 09:43

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部