实现效果:
Matlab
clc; clear;
filename = 'sri.xlsx'; % 确认文件路径
data = readtable(filename);
datavalue = data{:,2:end};
datavalue = datavalue';
fig = figure('Position', [0, 0, 1500, 900]);
indexString = ["(a)","(b)","(c)","(d)","(e)","(f)","(g)",];
subplotName = ["h1","h2","h3","h4","h5","h6","h7"];
for i = 1:7
subplot(4,2,i);
years = datavalue(:,1);
values = datavalue(:,i+1);
coefficients = polyfit(years, values, 1);
k = coefficients(1);
b = coefficients(2);
% 计算Y轴上下限值,将其设置为最大值和最小值的 1.1 倍
y_max = max(values) * 1.3;
y_min = min(values) * 1.3;
plot(years, values, 'o-', 'MarkerSize', 4, 'MarkerFaceColor', '#58CCFA', 'Color', '#58CCFA', 'LineWidth', 1.5);
hold on;
plot(years, k*years + b, 'r--', 'LineWidth', 1);%拟合线
xlim([1960 2018]);
xtick_values = 1960:10:2010;
if ~ismember(2018, xtick_values)
xtick_values = [xtick_values, 2018];
end
xticks(xtick_values);
ylabel('SRI', 'FontSize', 12);
ylim([y_min y_max]); % 设置Y轴上下限值
grid on;
yrange = ylim; % 获取当前子图的y轴值域范围
text(1961, 0.9 * yrange(2),indexString(i), 'FontSize', 14, 'HorizontalAlignment', 'left', 'VerticalAlignment', 'top'); % 调整文本位置坐标
ax = gca;
ax.FontSize = 12;
annotation('textbox', [ax.Position(1), ax.Position(2), ax.Position(3), ax.Position(4)], 'String', sprintf('k = %.4f, b = %.2f', k, b), 'FontSize', 14, 'EdgeColor', 'none', 'Color', 'black', 'HorizontalAlignment', 'center'); % 调整注释框位置
hold off;
end
% 在第 8 个子图位置添加文本
subplot(4,2,8);
str = ["(a):华北湿润半湿润暖 (b):西北荒漠地区";...
"(c):华中华南湿润亚热 (d):东北湿润半湿润温";...
"(e):内蒙草原地区 (f):青藏高原";...
"(g):华南湿润热带地区"];
text(0.15, 0.4, sprintf('%s\n', str{:}), 'FontSize', 14, 'HorizontalAlignment', 'left', 'VerticalAlignment', 'middle');
axis off; % 关闭坐标系显示
print(fig, 'data.tif', '-dtiff', '-r2000'); % 保存为 TIFF 文件,300 DPI 分辨率