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.
Thank you for your help! :)
+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
Use various text properties to change the font size, or text format etc...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With