# MATLAB绘图技巧-折线图绘制

% 允许曲线数据点数不一致

curveType = myData.testData{1};

x = myData.testData{2}; % FPR

y = myData.testData{3}; % TPR

numCurve = length(curveType);

% -------------------

% 设定绘制曲线类型数（10类）

LineType={'r-o','b-v','g:^','c-d','m--<','k:*','y-d','r-.>','g-.p','b-.h'};% 颜色/线型

lineWidth = 2; fontSize = 12;% 线宽/字号

% Plot the curve

hold on

for i = 1: numCurve

lineMaker = LineType{i};

plot(x{i}, y{i}, lineMaker, 'LineWidth', lineWidth);

end

% -------------------

title('ROC curve','FontSize',14);

% Set label and the location\font size of legend

xlabel('False positive rate/FPR', 'FontName','Times New Roman','FontSize',fontSize);

ylabel('True positive rate/TPR', 'FontName','Times New Roman','FontSize',fontSize);

xlim([0, 1]);   ylim([0, 1]);

set(gca, 'FontSize',fontSize);

h = legend(curveType{:});  %图例位置，字体和字号

set(h, 'Location', 'SouthEast', 'FontSize', fontSize, 'Fontname', 'Times New Roman');

% -------------------

defualtAxes % 图形修饰，包括坐标轴，网格等

% -------------------

function defualtAxes

ax = gca; hold on; box on

ax.XGrid ='on';

ax.YGrid ='on';

ax.XMinorTick ='on';

ax.YMinorTick ='on';

ax.LineWidth = 1.2;

ax.GridLineStyle = ':';

%ax.FontName='Cambria';

ax.FontSize = 12;

ax.GridAlpha = .3;

end

https://blog.sciencenet.cn/blog-425437-1419680.html

## 全部精选博文导读

GMT+8, 2024-9-11 04:50