I’m having a really strange issue with matplotlib. Plotting some points looks like this:
When I switch to a log scale on the y-axis, some of the points are not connected:
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()
Advertisement
Answer
log(0)
is undefined. I’m guessing matplotlib just ignores the NaN
s which crop up here.