MATLAB绘制论文插图

1. 准备绘图数据
%%
% 1. Data preparation

% x-data
x = linspace(1,10,20);
x_label = 'x';
% y-data: two sets of data
y = 5*rand(2,20); 
% 需要绘制曲线的条数
line_num = size(y,1);
y_label = 'y';
2.绘制曲线

颜色
r 红色
g 绿色
b 蓝色
k 黑色

线型
- 实线(默认)
-- 双划线
: 虚线
·- 点划线

%%
% 2. Plot Figure

fig = figure;
ax = axes(fig);

line_styles = {'-', '--', ':', '-.'};
line_colors = {'r','k','g'};
markers = {'o', 'square', '^', 'diamond', ...
    'o', 'square', '^', 'diamond'};
marker_colors = { ...
    [69, 117, 180] / 255, ... 
%     [145, 191, 219] / 255, ...
%     [224, 243, 248] / 255, ...
%     [254, 224, 144] / 255, ...
%     [252, 141, 89] / 255, ...
%     [215, 48, 39] / 255, ...
    [254, 224, 144] / 255
    };

for num = 1:line_num
    l{num} = plot(ax, x(1,:), y(num,:));
    l{num}.Marker = markers{num};
    l{num}.MarkerFaceColor = marker_colors{num};
    l{num}.MarkerEdgeColor = 'k';
    l{num}.MarkerSize = 4;
    l{num}.LineStyle = line_styles{num};
    l{num}.LineWidth = 1;
    l{num}.Color = 'k';
    hold on
end
 
legend('A','B') % 曲线名称
leg = legend(ax);
3. 调整图片
%%
% 3. Adjust Figure

fig.Units = 'centimeters';
fig.Position(3:4) = [7, 5.25]; % 图片大小:7cm x 5.25cm
fig.Color = [1.0, 1.0, 1.0]; % background color

% axes position and size: x y width height
ax.Units = 'centimeters';
ax.Position = [1.4, 1, 5.25, 4];
ax.LineWidth = 1;
ax.FontName = 'Times New Roman'; 
ax.FontSize = 10;
ax.TickLabelInterpreter = 'latex';

ax.XLabel.String = x_label;
ax.XLabel.Units = 'normalized';
ax.XLabel.Position(1:2) = [0.5, -0.125];
ax.XLabel.Interpreter = 'latex';
ax.XLim(1) = 0;

ax.YLabel.String = y_label;
ax.YLabel.Units = 'normalized';
ax.YLabel.Position(1:2) = [-0.15, 0.5];
ax.YLabel.Interpreter = 'latex';
ax.YLim(1) = 0;

% tick 刻度
ax.XMinorTick = 'on';
ax.YMinorTick = 'on';
ax.TickLength(1) = 0.02;

% legend 
leg.Interpreter = 'latex';
leg.Location = 'best'; % legend位置,右上角可以改为northeast
leg.Box = 'off';

% print(fig, '01', '-dsvg'); % 保存为.svg格式
4. 绘制结果
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。