Matlab论文插图绘制模板第97期—多子图(Subplot)

在之前的文章中,分享了很多Matlab单一论文插图的绘制模板。

若是想把很多张图,比如折线图、柱状图、饼图等等,画在同一张画布上,该怎么操作呢?

本期就来分享一下多子图的绘制模板。

先来看一下成品效果:

特别提示:本期内容『数据+代码』已上传资源群中,加群的朋友请自行下载。有需要的朋友可以关注同名公号【阿昆的科研日常】,后台回复关键词【绘图桶】查看加入方式


模板中最关键的部分内容

1. 数据准备

此部分主要是读取原始数据

% 读取数据load data.mat

2. 颜色定义

作图不配色就好比做菜不放盐,总让人感觉少些味道。

但颜色搭配比较考验个人审美,需要多加尝试。

这里直接使用TheColor配色工具中的SCI权威配色库

%% 颜色定义map = TheColor('sci',2064,'map',10);map = flipud(map);C = map([1 2 3 6],1:3);C1 = map(1,1:3);C2 = map(2,1:3);C3 = map(3,1:3);C4 = map(6,1:3);

3. 多子图绘制

通过‘subplot’命令,在各个分块位置创建子图坐标区,结合前面分享的论文插图绘制模板,将每个子图的绘制视为完整的单一论文插图分别进行绘制,从而完成多子图绘制

%%%% 绘制带误差棒的柱状图 %%%%subplot(2,2,1)hold onx = 1:4;GO = bar(x,bardata,0.6,'EdgeColor','none','LineWidth',1);for ii = 1:4    er = errorbar(x(ii),bardata(ii),barerr(ii),'CapSize',20);     er.Color = C(ii,:);      er.LineWidth = 1.5;    er.LineStyle = 'none';endhTitle = title('Bar with Errorbar');hXLabel = xlabel('Samples');hYLabel = ylabel('RMSE (m)');% 细节优化GO.FaceColor = 'flat';GO.CData(1,:) = C1;GO.CData(2,:) = C2;GO.CData(3,:) = C3;GO.CData(4,:) = C4;set(gca, 'Box', 'off', ...                                   % 边框         'Layer','top',...                                   % 图层         'LineWidth', 1,...                                  % 线宽         'XGrid', 'off', 'YGrid', 'off', ...                 % 网格         'TickDir', 'out', 'TickLength', [.015 .015], ...    % 刻度         'XMinorTick', 'off', 'YMinorTick', 'off', ...       % 小刻度         'XColor', [.1 .1 .1],  'YColor', [.1 .1 .1],...     % 坐标轴颜色         'YTick', 0:0.1:1,...                                % 坐标轴刻度         'Ylim' , [0 0.6], ...         'Xlim' , [0.3 4.7], ...         'XTick', 1:4,...         'Xticklabel',{'S1' 'S2' 'S3' 'S4' },...         'Yticklabel',{0:0.1:1})set(gca, 'FontName', 'Arial', 'FontSize', 9)set([hXLabel, hYLabel], 'FontSize', 9, 'FontName', 'Arial')set(hTitle, 'FontSize', 12, 'FontWeight' , 'bold')%%%% 绘制折线图 %%%%subplot(2,2,2)x = 1:8;p = plot(x,linedata);hTitle = title('Line Plot');hXLabel = xlabel('XAxis');hYLabel = ylabel('YAxis');% 细节优化MarkerL = {'v','o','^','s'};for i = 1:4    set(p(i),'LineStyle','-','Marker',MarkerL{i},'LineWidth',2.5,'Color',C(i,1:3))endset(gca, 'Box', 'off', ...                                % 边框         'LineWidth', 1,...                               % 线宽         'XGrid', 'off', 'YGrid', 'off', ...              % 网格         'TickDir', 'out', 'TickLength', [.015 .015], ... % 刻度         'XMinorTick', 'off', 'YMinorTick', 'off', ...    % 小刻度         'XColor', [.1 .1 .1],  'YColor', [.1 .1 .1])     % 坐标轴颜色set(gca, 'XTick', 0:1:8,  'YTick', 0:20:80,...            % 刻度位置、间隔         'Xlim' ,[0 8],'Ylim' ,[0 60], ...                % 坐标轴范围         'Xticklabel',{0:1:8},...                         % X坐标轴刻度标签         'Yticklabel',{0:20:80})                          % Y坐标轴刻度标签hLegend = legend(p, ...                 'Samp1', 'Samp2','Samp3','Samp4', ...                 'Location', 'northeast'); set(gca, 'FontName', 'Arial', 'FontSize', 9)set([hLegend, hXLabel, hYLabel], 'FontSize', 9, 'FontName', 'Arial')set(hTitle, 'FontSize', 12, 'FontWeight' , 'bold')%%%% 绘制饼图 %%%%subplot(2,2,3)pie(Piedata, Pieexplode)hTitle = title('Pie chart');% 细节优化colormap(C)th = findobj(gca, 'Type', 'text');set(th, 'FontName', 'Arail', 'FontSize', 10)set(hTitle, 'FontSize', 12, 'FontWeight' , 'bold')%%%% 绘制堆叠图 %%%%subplot(2,2,4)x = 1:13;GO = bar(x,stackeddata,0.8,'stacked','EdgeColor','k');hTitle = title('Stacked bar chart');hXLabel = xlabel('Samples');hYLabel = ylabel('RMSE (m)');% 细节优化GO(1).FaceColor = C1;GO(2).FaceColor = C2;GO(3).FaceColor = C3;GO(4).FaceColor = C4;GO(1).ShowBaseLine='off';set(gca, 'Box', 'off', ...                                         % 边框         'LineWidth', 1, ...                                       % 线宽         'XGrid', 'off', 'YGrid', 'off', ...                       % 网格         'TickDir', 'out', 'TickLength', [.015 .015], ...          % 刻度         'XMinorTick', 'off', 'YMinorTick', 'off', ...             % 小刻度         'XColor', [.1 .1 .1],  'YColor', [.1 .1 .1])              % 坐标轴颜色set(gca, 'YTick', 0:0.3:1.8,...         'Ylim' , [0 1.5], ...         'XTick', 1:13,...         'Xticklabel',{1:13},...         'Yticklabel',{0:0.3:1.8}) hLegend = legend([GO(1),GO(2),GO(3),GO(4)], ...                 'A', 'B', 'C', 'D', ...                 'Location', 'northeast');set(gca, 'FontName', 'Arial', 'FontSize', 9)set([hLegend,hXLabel, hYLabel], 'FontName', 'Arial', 'FontSize', 9)set(hTitle, 'FontSize', 12, 'FontWeight' , 'bold')

4. 图像输出

绘制完成后,以期刊所需分辨率、格式输出图片

%% 图片输出figW = figureWidth;figH = figureHeight;set(figureHandle,'PaperUnits',figureUnits);set(figureHandle,'PaperPosition',[0 0 figW figH]);fileout = 'test';print(figureHandle,[fileout,'.png'],'-r300','-dpng');

以上。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值