I want to make a plot like this one in MATLAB:
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
I want to make a plot like this one in MATLAB:
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
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)
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: