python - 情节:TypeError:“复杂”类型的对象不是 JSON 可序列化的
问题描述
# Now plot
tot = sum(eig_vals)
var_exp = [(i / tot)*100 for i in sorted(eig_vals, reverse=True)]
cum_var_exp = np.cumsum(var_exp)
trace1 = Bar(
x=['PC %s' %i for i in range(1,5)],
y=var_exp,
showlegend=False)
trace2 = Scatter(
x=['PC %s' %i for i in range(1,5)],
y=cum_var_exp,
name='cumulative explained variance')
data = Data([trace1, trace2])
layout=Layout(
yaxis=YAxis(title='Explained variance in percent'),
title='Explained variance by different principal components')
fig = Figure(data=data, layout=layout)
#display(data)
py.iplot(fig)
给我这个错误:---> 25 py.iplot(fig) TypeError: Object of type 'complex' is not JSON serializable
有关如何修复的任何帮助?
解决方案
推荐阅读
- python - 运行 Django 服务器时出错,ModuleNotFoundError: No module named 'mysite.myapp'(已解决)
- swift - 为什么我会收到“从 '[String]' 转换为不相关的类型 'String' 总是失败”错误?
- python - 需要帮助计算输入中的字母
- mongodb - MongoDB:如何找到具有最小值和 $lt 值的相同类型的文档
- c++ - strcpy_s 函数在我的代码中不起作用
- android - 如何使用 aapt / apktool 重命名 apk 包名称?
- python - 无法在 Python Selenium 中正确使用 WebDriverWait 库
- python - 屏蔽图像时在函数'cv :: binary_op'中出错openCV
- kivy - 尝试在 MDDialog 上创建按钮时出现属性错误
- javascript - 有没有办法用 JavaScript 模拟按 Ctrl+A?