1

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

EBH
  • 10,350
  • 3
  • 34
  • 59
Joe
  • 109
  • 1
  • 8
  • What kind of data you have? – EBH Sep 12 '16 at 07:56
  • It look more like a diagram, not a true plot, so I don't think that matlab will be the perfect tool for that. – obchardon Sep 12 '16 at 07:57
  • 1
    same info as the plot above ... What you suggest ? Which tool is suitable? – Joe Sep 12 '16 at 08:00
  • 1
    All kind of presentation program. Of course it's possible to do that with matlab, but, in my opinion, you have better to use a dedicated program. – obchardon Sep 12 '16 at 08:04
  • Depending on your operating system there are many softwares to do so. Use what you already have, such as PowerPoint or LibreOffice Draw. – Erfan Sep 12 '16 at 08:06
  • 1
    You can even use [Google Drawing](https://docs.google.com/drawings/d/1V9-Ec-I906-wXpdhpFGCWECJO6lL5qGOsU0vRoXqes0/edit?usp=sharing) – EBH Sep 12 '16 at 08:13
  • @EBH God bless you man ,, thank you ,, it is so helpful ... – Joe Sep 12 '16 at 08:31

2 Answers2

3

As mentioned in comments, this is better to do this in some other program (would be easier and better looking). But if you should do need to do it in Matlab, something like this would do it.

% 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)
NLindros
  • 1,683
  • 15
  • 15
  • 1
    This throws an error: _"There is no HeadWidth property on the DoubleEndArrow class"_, there are `Head1Width` and `Head2Width`, and the same for `HeadLength`. But, because `arrowType{k}` mix to different types of arrows, if you simply change these properties it will throw an error on the `Arrow` class. – EBH Sep 12 '16 at 09:56
  • @EBH At least for earlier Matlab versions, the propery HeadWidth (or HeadLength) is reinterpreted to Head1Width and Head2With for a double arrow annotation items. So for example by setting `set(h, 'HeadWidth',6)` both `Head1Width` and `Head2Width` would change. But I haven't updated to any of the latest Matlab versions, so perhaps it have changed. – NLindros Sep 12 '16 at 10:47
  • Well, there is nothing like this mentioned in the [docs](http://www.mathworks.com/help/matlab/ref/annotationdoublearrow-properties.html#property_head1length). BTW I use R2015a. Anyway I upvote for the effort :) – EBH Sep 12 '16 at 11:22
  • Probably previously hidden in some the dark, undocumented place. When I probe for *all* properites for the annotation (arrow) handle, `get(get(classhandle(handle(H)),'properties'),'Name')` Head1Width, Head2Width *and* HeadWidth emerges. – NLindros Sep 12 '16 at 12:10
2

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

EBH
  • 10,350
  • 3
  • 34
  • 59