Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to plot axis values with different (alternating) heights?

Tags:

plot

matlab

I like to plot in MATLAB a fourier-transformated signal. Via set(gca,'xtick',peaks,'FontSize',12); i can show the peak values at the x-axis. But sometimes, the peaks are too close together and the text showing the peak values is merging together with its neighbours. I have searched the web, but maybe asked the wrong question :) So my question is: How can i plot the peaks with alternating heights, like shown in the picture below? I prefer the use of 1 x-axis.

enter image description here

Thank you for your help! :)

like image 708
Aureon Avatar asked Jul 26 '13 16:07

Aureon


1 Answers

+1 for the interesting question.

Here's a way to do that, maybe not the most elegant, but shows the logic and make it happen:

x=0:pi/10:pi;
plot(x,sin(x));

set(gca, 'XTick', x, 'XTickLabel', cell(numel(x),1));
yl=get(gca,'YLim');
for n=1:numel(x)
    if mod(n,2)
       text(x(n), yl(1), {num2str(x(n)),''},'HorizontalAlignment','Center','VerticalAlignment','Top');
    else
       text(x(n), yl(1), {'',num2str(x(n))},'HorizontalAlignment','Center','VerticalAlignment','Top');
    end
end

enter image description here

Use various text properties to change the font size, or text format etc...

like image 150
bla Avatar answered Nov 03 '22 13:11

bla