Warning: converting a masked element to nan

2019-07-25 13:29发布

问题:

I am a beginner, so please bear with me. I make a violin plot with "five violins" but because of some reason, the last violin is not drawn and I get the error message:

/home/leo/anaconda3/lib/python3.6/site-packages/numpy/ma/core.py:4185: UserWarning: Warning: converting a masked element to nan.

I don't understand why I get this message because I didn't use a mask for any array. So what does it actually mean? Also some more warnings like:

Invalid value encountered in percentile

I guess it is just the ST_dist what makes problems and I don't know why, because I do nothing different then in the other lists.
Here is my code:

import numpy as np
import matplotlib.pyplot as plt

CD_dist=[]
CC_dist=[]
IM_dist=[]
IC_dist=[]
ST_dist=[]

fig,(axes1,axes2) = plt.subplots(nrows=2,ncols=1,figsize=(10,20))  

for t in range(0,len(D)):
    for la in range(0,len(lat_reg)):
       for lo in range(0,len(lon_reg1)):

         if(reg_ran[t,la,lo]==1):
            CD_dist.append(D[t,indlat,indlon])
         elif(reg_ran[t,la,lo]==2):
            CC_dist.append(D[t,indlat,indlon])
         elif(reg_ran[t,la,lo]==3):
            IM_dist.append(D[t,indlat,indlon])   
         elif(reg_ran[t,la,lo]==4):
            IC_dist.append(D[t,indlat,indlon])
         elif(reg_ran[t,la,lo]==5):
            ST_dist.append(D[t,indlat,indlon])
         elif(reg_ran[t,la,lo]==6):
            ST_dist.append(D[t,indlat,indlon])
         elif(reg_ran[t,la,lo]==7):
            ST_dist.append(D[t,indlat,indlon])
         elif(reg_ran[t,la,lo]==8):
            ST_dist.append(D[t,indlat,indlon])

ST_dist=list(np.array(ST_dist).astype(np.float32))

dist=[CD_dist,CC_dist,IM_dist,IC_dist,ST_dist]

axes1.boxplot(dist)
axes2.violinplot(dist,showmeans=False,showmedians=True)

pfile.savefig()
plt.close()  

I tried to mask the array and removed the masked values with the line ST_dist=list(np.array(ST_dist).astype(np.float32)). But it does not work.

That's what the plot looks like up to now.
Have anyone an idea why ST_dist is not plotted?