不绘制';零';matplotlib[Python,Jupyter笔记本]中饼图列表中的值

不绘制';零';matplotlib[Python,Jupyter笔记本]中饼图列表中的值,python,matplotlib,Python,Matplotlib,我只是需要帮助,不要使用python在matplotlib中按照标题在饼图上绘制“零”值 我曾尝试使用另一篇文章中的解决方案,但我不断发现无法将浮点NaN转换为整数错误 其他职位的解决方案: values = [3, 5, 0, 3, 5, 1, 4, 0, 9] def zero_to_nan(values): """Replace every 0 with 'nan' and return a copy.""" return [float('nan') if x==0 el

我只是需要帮助,不要使用python在matplotlib中按照标题在饼图上绘制“零”值

我曾尝试使用另一篇文章中的解决方案,但我不断发现无法将浮点NaN转换为整数错误

其他职位的解决方案:

values = [3, 5, 0, 3, 5, 1, 4, 0, 9]

def zero_to_nan(values):
    """Replace every 0 with 'nan' and return a copy."""
    return [float('nan') if x==0 else x for x in values]

print(zero_to_nan(values))
这是我的代码的简化版本:

#For plotting and visualization
from IPython.display import display
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline

#Possible solution - however i get error cannot convert float NaN to integer 
error

sample = [innercitybypass,others,kingsfordcount] ##E.g.[0,1,2]
def zero_to_nan(sample):
    return [float('nan') if x==0 else x for x in sample]

labels = ['InnerCityBypass','OtherRds','KingsfordRd']
###sizes = [innercitybypass,others,kingsfordcount]
sizes = zero_to_nan(sample)
#Set different colors
colors = ['green','red','blue']

plt.pie(sizes, labels=labels, colors=colors, autopct='%1.1f%%', 
startangle=140)
plt.axis('equal')
plt.show()
任何帮助都将不胜感激,谢谢

使用numpy.nan(确保导入numpy)


谢谢你的回复,不过我还是得到了同样的错误。我说得对吗?sizes=zero_to_nan(示例),是的,我尝试过添加括号,sizes=(zero_to_nan(示例)),但它仍然给我ValueError:无法将浮点nan转换为整数我也有这个问题!如果输入数组中存在任何NAN,则plt.pie()返回相同的错误。
import numpy as np

def zero_to_nan(sample):
    return [np.nan if x==0 else x for x in sample]