4

I'm having a really strange issue with matplotlib. Plotting some points looks like this:

regulargraph

When I switch to a log scale on the y-axis, some of the points are not connected:

logscale

Is this a bug? Am I missing something? Code is below. Comment out the log scale line to see the first graph.

import matplotlib.pyplot as plt

fig = plt.figure()
ax1 = fig.add_subplot(111)

x = [1.0, 2.0, 3.01, 4.01, 5.01, 6.01, 7.04, 8.04, 9.04, 10.05,
     11.05, 12.09, 13.17, 14.18, 15.73, 16.74, 17.74, 18.9, 19.91,
     20.94, 22.05, 23.15, 24.33, 25.48, 26.51, 27.58, 28.86, 29.93,
     30.93, 32.23, 33.25, 34.26, 35.27, 36.29, 37.33, 38.35, 39.36,
     40.37, 41.37]
y = [552427, 464338, 446687, 201960, 227238, 265140, 148903, 134851,
     172234, 120263, 115385, 100671, 164542, 171176, 28, 356, 0, 0,
     195, 313, 9, 0, 132, 0, 249, 242, 81, 217, 159, 140, 203, 215,
     171, 141, 154, 114, 99, 97, 97]

ax1.plot(x, y, c='b', marker='o')

ax1.set_yscale('log')
plt.ylim((-50000, 600000))
plt.show()
0

2 Answers 2

7

log(0) is undefined. I'm guessing matplotlib just ignores the NaNs which crop up here.

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

2 Comments

I guess the workaround would be very dependent on where you want those points to show up.
ah, right, because on a log scale, 0 would end up being at the infinitely bottom of the y-axis. Setting them to 1 should work in my case, thanks!
3

You can try to use ax1.set_yscale('symlog')

Plot of your data with symlog scale

Comments

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.