Warning: converting a masked element to nan

我只是一个虾纸丫 提交于 2020-01-05 12:57:32

问题


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?

来源:https://stackoverflow.com/questions/43930235/warning-converting-a-masked-element-to-nan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!