Search code examples
matlabplotmatlab-figure

How to plot an analysis picture in matlab


I want to make a plot like this one in MATLAB:

enter image description here

I searched in google but I did not find any way to do it in MATLAB.
How can I do that figure in MATLAB? Does not need to be exactly the same plot but the same info must be involved in the plot. Thanks


Solution

  • It is too long for a comment, so here is a fixed (and without loops) version of @nilZ0r answer (if you are going to accept any answer, accept his). I annotated the changes:

    % 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)
    

    And the result:

    Frequency