2

I have a small code producing the following picture with this code:

Code 1:

hist, rhist = np.histogram(r, bins=40, range=(0, 0.25))
hist = -hist/np.trapz(rhist[:-1],hist)
plt.plot(rhist[:-1], hist)

Output of code 1: enter image description here

Then I try setting the plot to have a logarithmic Y axis so that I can recognise small peaks more clearly. This is the result.

Code 2:

hist, rhist = np.histogram(r, bins=40, range=(0, 0.25))
hist = -hist/np.trapz(rhist[:-1],hist)
plt.semilogy(rhist[:-1], hist)

Output of code 2: enter image description here

As you can see, part of my plot disappears. There are 40 bins, I can however only count about 15 in the new plot. Any help will be greatly appreciated. I am using Enthought Canopy of the latest version for academic use. E.

UPDATE: I did find a similar question here, old, dead and unanswered though.

Community
  • 1
  • 1
erthy
  • 81
  • 9

3 Answers3

1

I'm pretty sure it's just not plotting those values because they are zero.

Log(0) = -Infinity.

Plotting that is going to make your graph look pretty rubbish...

will
  • 10,260
  • 6
  • 46
  • 69
1

Issue plt.yscale('symlog') at the end of your plotting. See here for a description of 'symlog'.

Community
  • 1
  • 1
esmit
  • 1,748
  • 14
  • 27
0

A common visual trick to "display" zero in log scale is to use a very small value instead:

plt.semilogy(rhist[:-1], hist+1e-6)

In this case beaware of correct interpretation of plot though.

user2304916
  • 7,882
  • 5
  • 39
  • 53
  • Good idea as well. I'd upvote you but I don't have the rep, haha. – erthy Jul 16 '13 at 02:32
  • If you're going to do this, then this really isn't how you should do it... You should use the `nonposy` argument. See [this answer](http://stackoverflow.com/a/3513150/432913) for more info. – will Jul 16 '13 at 12:17