如何在matlab中绘制分析图片

时间:2016-09-12 07:50:00

标签: matlab plot matlab-figure

我想在MATLAB中制作这样的情节:

enter image description here

我在谷歌搜索但我没有找到任何方法在MATLAB中做到这一点 我怎样才能在MATLAB中做这个数字?不需要完全相同的绘图,但绘图中必须包含相同的信息。 感谢

2 个答案:

答案 0 :(得分:3)

正如评论中所提到的,在其他一些程序中这样做会更好(会更简单,更好看)。但是如果你应该在Matlab中需要这样做,那么就会这样做。

% Create figure and axes
f = figure(1); clf
a = axes;
aPos = [0.1 0.1 0.03 0.8];
gbColor = [0 1 0.7];
yTick = logspace(4,10,7);
YTickLlb = {'0.01Mz','0.1 MHz','1.0 MHz','10 MHz','100 MHz','1 GHz',''};
set(a,...
    'Position', aPos, ...
    'YAxisLocation','right', ...
    'YLim', yTick([1 end]), ...
    'YScale','log',...
    'YTickLabel',YTickLlb,...
    'XTick',[], ...
    'Box','on',...
    'Color', gbColor)
title('Frequency')

% Plot text
txtFontSize = 12;
txt = {'Hearing threshold (20 kHz)','Therapeutic applications','Medical imaging','Ultrasound microscopy'};
txtPos = [2e4 1e6 2e7 1e9];
txtOffset = 5;
for k = 1:length(txt)
    t(k) = text(txtOffset, txtPos(k), txt{k},'FontSize', txtFontSize);
end

% Plot arrows (with figure as reference)
arrowPos = {[6 70]*1e6, [7 70]*1e8};
arrowType = {'doublearrow', 'arrow'};
arrowOffset = (aPos(1) + aPos(3)*txtOffset*0.9)*[1 1];
normYTick = linspace(0,1,length(yTick));
for k = 1:length(arrowPos)
    annotation(f, arrowType{k}, arrowOffset, interp1(yTick, normYTick, arrowPos{k})*aPos(4) + aPos(2),...
        'HeadStyle','Plain','HeadWidth',4, 'HeadLength', 4);
end

% Plot information text
text(7, yTick(end), '\lambda f = 1500 ms^{-1} in water','FontSize', txtFontSize)

答案 1 :(得分:2)

评论太长了,所以这里有一个固定的(没有循环)版本的@ nilZ0r答案(如果你要接受任何答案,接受他的)。我注释了这些变化:

% Create figure and axes
f = figure('Color',[1 1 1]); clf % <-- white background
a = axes;
aPos = [0.1 0.1 0.03 0.8];
gbColor = [0 1 0.7];
yTick = logspace(4,10,7);
YTickLlb = {'0.01MHz','0.1 MHz','1.0 MHz','10 MHz','100 MHz','1 GHz',''};
set(a,...
    'Position', aPos, ...
    'YAxisLocation','right', ...
    'YLim', yTick([1 end]), ...
    'YScale','log',...
    'YTickLabel',YTickLlb,...
    'XTick',[], ...
    'Box','on',...
    'Color', gbColor)
title('Frequency')

% Plot text
txtFontSize = 12;
txt = {'Hearing threshold (20 kHz)','Therapeutic applications',...
    'Medical imaging','Ultrasound microscopy'};
txtPos = [2e4 1e6 2e7 1e9];
txtOffset = 5;
% No need for a loop:
text(ones(numel(txtPos),1)*txtOffset, txtPos, txt,'FontSize', txtFontSize);

% Plot arrows (with figure as reference)
arrowPos = [[6 70]*1e6; [7 70]*1e8]; % <-- matrix instead of a cell array
% arrowType is deleted
arrowOffset = (aPos(1) + aPos(3)*txtOffset*0.9)*[1 1];
normYTick = linspace(0,1,length(yTick));
% two different calls to 'annotation', based on the arrow type:
annotation(f, 'doublearrow', arrowOffset, interp1(yTick, normYTick,...
    arrowPos(1,:))*aPos(4) + aPos(2),'HeadStyle','Plain','Head1Width',4,...
    'Head2Width',4, 'Head1Length', 4,'Head2Length', 4);
annotation(f, 'arrow', arrowOffset, interp1(yTick, normYTick,...
    arrowPos(2,:))*aPos(4) + aPos(2),'HeadStyle','Plain','HeadWidth',4,...
    'HeadLength',4);

% Plot information text
text(7, yTick(end), '\lambda f = 1500 ms^{-1} in water',...
    'FontSize', txtFontSize)

结果:

Frequency