pcolormesh with missing values?

前端 未结 3 995
[愿得一人]
[愿得一人] 2020-12-05 11:04

I have 3 1-D ndarrays: x, y, z

and the following code:

import numpy as np
import matplotlib.pyplot as plt
import scipy.interpolate as spinterp

## de         


        
3条回答
  •  猫巷女王i
    2020-12-05 11:26

    Got it. This seems round-about, but this was the solution:

    import numpy.ma as ma
    
    Zm = ma.masked_where(np.isnan(Z),Z)
    plt.pcolormesh(X,Y,Zm.T)
    

    If the Z matrix contains nan's, it has to be a masked array for pcolormesh, which has to be created with ma.masked_where, or, alternatively,

    Zm = ma.array(Z,mask=np.isnan(Z))
    

提交回复
热议问题