我对matplotlib有一个非常奇怪的问题。绘制一些点看起来像这样:
当我在y轴上切换到对数刻度时,某些点未连接:
这是一个错误吗?我错过了什么吗?代码如下。注释掉日志比例行以查看第一个图表。
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 :(得分:6)
log(0)
未定义。我猜matplotlib只是忽略了这里出现的NaN
。