使用numpy掩码数组进行绘图

时间:2019-06-26 06:15:13

标签: python numpy matplotlib

为什么matplotlib / numpy不会用线绘制未屏蔽的点?此问题仅以绘图为线。散点图可以工作。

import numpy as np
import matplotlib.pyplot as plt

x = np.ma.array([0, 1, 2, 3, 4])

x[[1, 3]] = np.ma.masked # issue is only when its set this way; but this is recommended in the docs
# x = np.ma.masked_where(x < 3) # this works fine for all plotting

plt.plot(x) # this shows nothing, but the axes are set correctly
plt.show()

plt.plot(x, "o") # this shows the points
plt.show()

0 个答案:

没有答案