Reputation: 1363
How can I properly plot a peak in Matlab with a given height? My current method:
x = linspace(0,500,500);
peaks = zeros(size(x));
peaks(50) = 5;
peaks(300) = 20;
peaks(302) = 17;
peaks(375) = 15;
plot(x,peaks)
which gives
But this is ugly, confusing when multiple lines are close and leads to problems when converting it to a log scale since log(0)=-Inf
. Is there a proper way of plotting peaks?
Context: I'm trying to analyse a spectogram (EDXS) to identify which material I'm working with.
Upvotes: 0
Views: 153
Reputation: 36710
Scaling the scale to log, you are asking Matlab to draw a line between -Inf and a positive value. Such lines are skipped.
To get a usable log plot, use points instead of lines:
plot(x,peaks,'x')
Another nice possibility to plot peaks is a stem
-plot
Upvotes: 1
Reputation: 14939
I think the reason why you only get single pixels in your log-plot is because most of your values are 0
. As log(0) = -Inf
, this can't be plotted.
I know nothing of spectogram analyses, but if you absolutely want to plot this with a logarithmic scale, is it possible to use a "base line" equal 1 (0 in a log scale). If so:
x = linspace(0,100);
peaks = ones(size(x));
peaks(10) = 5;
peaks(60) = 20;
peaks(75) = 15;
semilogy(x,peaks)
I guess that this will look more reasonable with your real data. Note: If you have values that are less than 1
, I would not go with this approach!
Upvotes: 0