学术资讯 » 学界研圈

  • 首 页
  • 期刊选题
  • 期刊点评
  • 期刊大全
  • 学人博客
  • 编辑征稿
  • 投稿选刊
  • 万维群组
  • 学术会议
  • 万维读书
  • SCI/E期刊
  • SSCI期刊
  • AHCI期刊
  • Matlab论文插图绘制模板第111期—带线标记的图

    阅读: 2023/9/11 10:55:45

    本期分享的是带线标记注释的图。

    模板中最关键的部分内容:

    1. 数据准备

    此部分主要是读取原始数据并初始化绘图参数。

    % 读取数据

    load data.mat

    % 初始化绘图参数

    X = data(:,1);

    Y = data(:,2);

    2. 颜色定义

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

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

    这里直接使用TheColor配色工具中的XKCD配色库:

    C = TheColor('xkcd',[454 384 270 627]);

    C1 = C(1,1:3);

    C2 = C(2,1:3);

    C3 = C(3,1:3);

    C4 = C(4,1:3);

    3. 带线标记的图绘制

    通过调用‘line’命令,绘制初始带线标记的图。

    % 原始数据绘制

    L = line(X,Y);

    % 标记线1绘制

    x = 100;

    y = Y(11);

    LL1 = line([x x 0], [0 y y]);

    S1 = scatter(x,y,60,C2,'filled');

    % 标记线2绘制

    x = 50;

    y = Y(6);

    LL2 = line([x x 0], [0 y y]);

    S2 = scatter(x,y,60,C3,'filled');

    % 标记线3绘制

    x = 25;

    y = Y(4)-Y(3);

    LL3 = line([x x 0], [0 y y]);

    S3 = scatter(x,y,60,C4,'filled');

    hTitle = title('Closed loop response');

    hXLabel = xlabel('Time');

    hYLabel = ylabel('Tank temperature (normalized)');

    4. 细节优化

    为了插图的美观,将初始带线标记的图赋上之前选择的颜色,并对坐标轴细节等进行美化:

    % 赋色及属性调整

    set(L,'LineStyle','-','LineWidth',3, 'Color',C1)

    set(LL1,'LineStyle','-.','LineWidth',2.5, 'Color', C2)

    set(LL2,'LineStyle','-.','LineWidth',2.5, 'Color', C3)

    set(LL3,'LineStyle','-.','LineWidth',2.5, 'Color', C4)

    % 坐标区调整

    set(gca, 'Box', 'off', ... % 边框

    'Layer','top',... % 图层

    'LineWidth',1,... % 线宽

    'XGrid', 'off', 'YGrid', 'off', ... % 网格

    'TickDir', 'out', 'TickLength', [0.01 0.01], ... % 刻度

    'XMinorTick', 'off', 'YMinorTick', 'off', ... % 小刻度

    'XColor', [.1 .1 .1], 'YColor', [.1 .1 .1]) % 坐标轴颜色

    % Legend

    hLegend = legend([LL1,LL2,LL3], ...

    'Feature A','Feature B', 'Feature C',...

    'Location', 'southeast');

    % 字体和字号

    set(gca, 'FontName', 'Arial', 'FontSize', 10)

    set([hLegend,hXLabel,hYLabel], 'FontSize', 11, 'FontName', 'Arial')

    set(hTitle, 'FontSize', 12, 'FontWeight' , 'bold')

    % 背景颜色

    set(gcf,'Color',[1 1 1])

    % 添加上、右框线

    xc = get(gca,'XColor');

    yc = get(gca,'YColor');

    unit = get(gca,'units');

    ax = axes( 'Units', unit,...

    'Position',get(gca,'Position'),...

    'XAxisLocation','top',...

    'YAxisLocation','right',...

    'Color','none',...

    'XColor',xc,...

    'YColor',yc);

    set(ax, 'linewidth',1,...

    'XTick', [],...

    'YTick', []);

    设置完毕后,以期刊所需分辨率、格式输出图片。

    %% 图片输出

    figW = figureWidth;

    figH = figureHeight;

    set(figureHandle,'PaperUnits',figureUnits);

    set(figureHandle,'PaperPosition',[0 0 figW figH]);

    fileout = 'test';

    print(figureHandle,[fileout,'.png'],'-r300','-dpng');

    以上。

    转自:“阿昆的科研日常”微信公众号

    如有侵权,请联系本站删除!


    浏览(134)
    点赞(0)
    收藏(0)
  • 上一篇:环保所召开“超临界流体技术在农业废弃物处理中的应用与前景”国际学术研讨会

    下一篇:Matlab进阶绘图第27期—水平双向堆叠图

  • 首页

  • 文章

  • 期刊

  • 帮助

  • 我的

版权所有 Copyright@2023    备案号:豫ICP备2021036211号