matplotlib: Plot numpy arrays with None as values

前端 未结 2 1343
猫巷女王i
猫巷女王i 2021-01-05 09:34

I have an array that looks like:

k = numpy.array([(1.,0.001), (1.1, 0.002), (None, None), 
                 (1.2, 0.003), (0.99, 0.004)])

I

2条回答
  •  太阳男子
    2021-01-05 10:30

    You can filter you array doing:

    test = np.array([None])
    k = k[k!=test].reshape(-1, 2).astype(float)
    

    And then sum up the columns and make the plot. The problem of your approach is that you did not convert the None type to a numpy array, which did not allow the proper creation of the mask.

提交回复
热议问题