python - Plotly Python 图中的错误在哪里?
问题描述
我有如下代码:
goodCredit = data[data["Risk"] == 'good']
badCredit = data[data["Risk"] == 'bad']
bar1SA = go.Bar(
x = goodCredit["Saving accounts"].value_counts().index.values,
y = goodCredit["Saving accounts"].value_counts().values,
name='Good credit')
bar2SA = go.Bar(
x = badCredit["Saving accounts"].value_counts().index.values,
y = badCredit["Saving accounts"].value_counts().values,
name='Bad credit')
bar1CA = go.Box(
x=goodCredit["Checking account"].value_counts().index.values,
y=goodCredit["Checking account"].value_counts().values,
name='Good credit')
bar2CA = go.Box(
x=badCredit["Checking account"].value_counts().index.values,
y=badCredit["Checking account"].value_counts().values,
name='Bad credit')
data = [bar1SA, bar2SA, bar1CA, bar2CA]
fig = tls.make_subplots(rows=1, cols=2,
subplot_titles=('Count Saving Accounts','Count Checking account'))
fig.append_trace(bar1SA, 1, 1)
fig.append_trace(bar2SA, 1, 1)
fig.append_trace(bar1CA, 1, 2)
fig.append_trace(bar2CA, 1, 2)
fig['layout'].update(height=700, width=800, title='Saving Accounts and Checking account Exploration based on risk')
py.iplot(fig, filename='SAiCAdistribution')
结果如下:
代码中的错误在哪里,因为你可以看到第二个情节不好,它应该像第一个情节一样。
解决方案
当您说相似时,我假设您希望它们都是条形图。如果是这样,那么切换
bar1CA = go.Box(
x=goodCredit["Checking account"].value_counts().index.values,
y=goodCredit["Checking account"].value_counts().values,
name='Good credit')
bar2CA = go.Box(
x=badCredit["Checking account"].value_counts().index.values,
y=badCredit["Checking account"].value_counts().values,
name='Bad credit')
至
bar1CA = go.Bar(
x=goodCredit["Checking account"].value_counts().index.values,
y=goodCredit["Checking account"].value_counts().values,
name='Good credit')
bar2CA = go.Bar(
x=badCredit["Checking account"].value_counts().index.values,
y=badCredit["Checking account"].value_counts().values,
name='Bad credit')
应该做的伎俩。
推荐阅读
- java - 具有相同字符串的 JUnit 断言错误
- javascript - 在 JS 中修改样式绕过当前 styleSheets.cssRules lmitations 并在获取 ID 时使用循环
- java - 从 5.1.13 升级到 5.2.7 后 Spring Context 初始化失败并出现 StackOverflowError
- swift - 如何将 .share() 与主题 [Swift Combine] 一起使用
- android - Android WebView 删除页眉和页脚
- flutter - Flutter 稳定版 1.20.1 构建失败问题
- android - 检查 ArrayList 中是否存在用户 ID?
- netlogo - 试图确定与特定节点的链接
- chocolatey - 如何找出chocolatey安装的软件包文件的位置?
- .net - docker-in-docker 上免费的在线 gitlab 运行器