把这个代码改进一下 可以自由调整坐标轴数值字号大小
时间: 2024-03-18 19:41:00 浏览: 91
可以在脚本中添加如下代码来实现:
```
% 设置坐标轴字号大小
ax.XAxis.FontSize = 14;
ax.YAxis.FontSize = 14;
% 设置坐标轴标签字号大小
xlabel('Trace number', 'FontSize', 16);
ylabel('Time [s]', 'FontSize', 16);
% 设置 colorbar 标签字号大小
c.Label.FontSize = 16;
```
你可以根据需要修改字号大小的数值。完整代码如下:
```
% plot_Bscan.m % Script to plot EM fields from a gprMax B-scan % % Craig Warren
clear all, clc
[filename, pathname] = uigetfile('*.out', 'Select gprMax output file to plot B-scan', 'MultiSelect', 'on');
filename = fullfile(pathname, filename);
% Open file and read fields
if filename ~= 0
iterations = double(h5readatt(filename, '/', 'Iterations'));
dt = h5readatt(filename, '/', 'dt');
prompt = 'Which field do you want to view? Ex, Ey, or Ez: ';
field = input(prompt,'s');
fieldpath = strcat('/rxs/rx1/', field);
field = h5read(filename, fieldpath)';
time = linspace(0, (iterations - 1) * dt, iterations)';
traces = 0:size(field, 2);
fh1=figure('Name', filename);
clims = [-max(max(abs(field))) max(max(abs(field)))];
im = imagesc(traces, time, field, clims);
xlabel('Trace number', 'FontSize', 16);
ylabel('Time [s]', 'FontSize', 16);
c = colorbar;
c.Label.String = 'Field strength [V/m]';
c.Label.FontSize = 16;
ax = gca;
ax.FontSize = 14;
ax.XAxis.FontSize = 14;
ax.YAxis.FontSize = 14;
xlim([0 traces(end)]);
% Options to create a nice looking figure for display and printing
set(fh1,'Color','white','Menubar','none');
X = 60; % Paper size
Y = 30; % Paper size
xMargin = 0; % Left/right margins from page borders
yMargin = 0; % Bottom/top margins from page borders
xSize = X - 2*xMargin; % Figure size on paper (width & height)
ySize = Y - 2*yMargin; % Figure size on paper (width & height)
% Figure size displayed on screen
set(fh1, 'Units','centimeters', 'Position', [0 0 xSize ySize])
movegui(fh1, 'center')
% Figure size printed on paper
set(fh1,'PaperUnits', 'centimeters')
set(fh1,'PaperSize', [X Y])
set(fh1,'PaperPosition', [xMargin yMargin xSize ySize])
set(fh1,'PaperOrientation', 'portrait')
end
```
注意要在 `ax.FontSize` 的后面添加 `ax.XAxis.FontSize` 和 `ax.YAxis.FontSize`。
阅读全文