matlab绘图
双y坐标,条形图+折线图,y轴刻度值离散化
plot()与semilogy()对比
效果:
程序:
clear all;clc [num,txt,raw]=xlsread('matlab绘图数据.xlsx'); %读入数据 year=num(:,1); x=num(:,2); ux=num(:,3); ux1=num(:,4); ux2=num(:,5); ux3=num(:,6); figure(1); yyaxis left; bar(year,x, 0.5) %绘制条形图,0.5为条形图宽度 set(gca,'ycolor','k'); %左边Y轴颜色 axis([2010,2020,0,350]); %限制x,y轴坐标值范围 % hold on; yyaxis right; % plot(year,ux,'k-s',year,ux1,'g-d',year,ux2,'b-o',year,ux3,'r-+');%绘制折线图(不扩展y轴) semilogy(year,ux,'k-s',year,ux1,'g-d',year,ux2,'b-o',year,ux3,'r-+');%绘制折线图 set(gca,'YLim',[-1 0.7]); mu=[0.0008348 0.002 0.005 0.01 0.02 0.05 0.1 0.2 0.4 0.7]; % 设置刻度值 set(gca,'ytick',mu,'yticklabel',{'0' '0.002' '0.005' '0.01' '0.02' '0.05' '0.1' '0.2' '0.4' '0.7'}); %纵坐标设置 % set(gca,'ytick',{'0' '0.002' '0.005' '0.01' '0.02' '0.05' '0.1' '0.2' '0.4' '0.7'}); set(gca,'ycolor','k'); %右边Y轴颜色 set(gca, 'YMinorTick', 'off') %去除没有刻度值的刻度线 axis([2010,2020,0,0.7]); legend('x','ux','ux1','ux2','ux3','orientation','horizontal'); %曲线注释 box off %删除上边框