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.

3 Answers 3

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...

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I did not even think about that and it is so obvious! :)
1

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

Comments

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.

2 Comments

Good idea as well. I'd upvote you but I don't have the rep, haha.
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 for more info.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.