科研论文中需绘制多组数据对比的折线图。本文给出Matlab绘制多组数据折线图的代码,可以满足期刊论文发表的绘图要求。显示效果如下:
可以在论文中多图合并,如下所示:
%% 绘图脚本
% 本代码最初是为了绘制算法的参数敏感度,大家可以简单借鉴。作者:蒋林志
% 输入数据
beta_all = [0.5619,0.5685,0.5667,0.5586,0.5494,0.5562,0.5440,0.5500,0.5455;
0.5685,0.5599,0.5541,0.5551,0.5545,0.5523,0.5551,0.5455,0.5496;
0.6014,0.6076,0.5969,0.5897,0.5858,0.5827,0.5813,0.5852,0.5706;
0.5856,0.5879,0.5833,0.5864,0.5837,0.5745,0.5737,0.5813,0.5757;
0.6049,0.6035,0.6074,0.5893,0.5870,0.5874,0.5912,0.5844,0.5879];
sel = 'my method';
cost_plot(sel,beta_all,'\beta'); % 调用函数
%% 绘图函数
function cost_plot(sel,cur_data,parameter)
%% 维数选择
% MNIST to USPS
Dim = [0:size(cur_data,2)-1];% x轴大小
t = tiledlayout(2,2,'TileSpacing','Compact'); % 设置图例位置
set(figure(1),'Position',[200,200,1000,260]);
% 设置颜色
c1 = [0,0,0]; % 黑色
c2 = [1,0,0]; % 红色
c3 = [0.105882352941176,0.619607843137255,0.466666666666667];% 绿色
c4 = [0.545098039215686,0,0.545098039215686];% 紫色
c5 = [0.254901960784314,0.411764705882353,0.882352941176471]; % 蓝色
% line1
Line1 = line(Dim(1:1:9),cur_data(1,1:9)*100);
set(Line1, 'LineStyle', '--','LineWidth', 1, 'Color', c1);
set(Line1, 'Marker', 'o','MarkerEdgeColor',c1,'MarkerFaceColor','w','MarkerSize',6);
% line2
Line2 = line(Dim(1:1:9),cur_data(2,1:9)*100);
set(Line2, 'LineStyle', '--','LineWidth', 1, 'Color', c2);
set(Line2, 'Marker', '+','MarkerEdgeColor',c2,'MarkerFaceColor','w','MarkerSize',6);
% line3
Line3 = line(Dim(1:1:9),cur_data(3,1:9)*100);
set(Line3, 'LineStyle', '--','LineWidth', 1, 'Color', c3);
set(Line3, 'Marker', '^','MarkerEdgeColor',c3,'MarkerFaceColor','w','MarkerSize',6);
% line4
Line4 = line(Dim(1:1:9),cur_data(4,1:9)*100);
set(Line4, 'LineStyle', '--','LineWidth', 1, 'Color', c4);
set(Line4, 'Marker', '*','MarkerEdgeColor',c4,'MarkerFaceColor','w','MarkerSize',6);
% line5
Line5 = line(Dim(1:1:9),cur_data(5,1:9)*100);
set(Line5, 'LineStyle', '--','LineWidth', 1, 'Color', c5);
set(Line5, 'Marker', 'd','MarkerEdgeColor',c5,'MarkerFaceColor','w','MarkerSize',6);
set(gca, 'Box', 'off', ... % 边框设置
'XGrid', 'off', 'YGrid', 'on', ... % 网格线调整
'TickDir', 'out', 'TickLength', [.01 .01], ... % 刻度调整
'XMinorTick', 'off', 'YMinorTick', 'off', ...
'XColor', [.1 .1 .1], 'YColor', [.1 .1 .1],...
'FontName', 'Times', 'FontSize', 9); % 坐标轴颜色
set(gca,'XTick',Dim) %x轴范围1-8,间隔1
set(gca,'XTicklabel',{'0.01','0.05','0.1','0.5','1', '1.5', '2', '5','10'});% 设置x轴刻度
legend('A1','B2','C3','D4','E5','Location','NorthOutside',...
'Orientation','horizon','FontName','Helvetica','FontSize',12,'FontWeight','normal'); %右上角标注
title(['Parameter sensitivity of ',sel],'FontName','Helvetica','FontSize',10,'FontWeight','normal') % 标题(可去掉)
xlabel(parameter, 'FontName','Helvetica','FontSize',10,'FontWeight','normal') %x轴坐标描述
ylabel('Accuracy(%)', 'FontName','Helvetica','FontSize',10,'FontWeight','normal') %y轴坐标描述
end
写作不易,如果对您有帮助请麻烦点个赞,十分感谢。