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

I like to draw a Fourier-transformed signal in MATLAB. Via set (gca, 'xtick', peaks, 'FontSize', 12); I can show the peak values ​​on the x axis. But sometimes the peaks are too close to each other, and the text showing the peak values ​​merges with its neighbors. I searched on the Internet, but maybe asked the wrong question :) So my question is: How can I build peaks with alternating heights, as shown in the figure below? I prefer to use 1 axis axis.

enter image description here

Thanks for the help!:)

+6
matlab plot
source share
1 answer

+1 for an interesting question.

Here is a way to do this, maybe not the most elegant, but shows the logic and does it:

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, text format, etc.

+7
source share

All Articles