【问题标题】:Where is mistake in Plotly Python plot?Plotly Python 情节中的错误在哪里?
【发布时间】:2020-06-11 22:33:33
【问题描述】:

我有如下代码:

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')

结果如下:

代码哪里出错了,因为你可以看到第二个情节不好,它应该和第一个情节相似。

【问题讨论】:

    标签: python pandas plotly seaborn


    【解决方案1】:

    当您说相似时,我假设您希望它们都是条形图。如果是,那么切换

    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')
    

    应该可以解决问题。

    【讨论】:

    • 哈哈...哇,我不可能没有找到这个解决方案,谢谢!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-04-11
    • 1970-01-01
    • 2016-09-29
    • 2015-05-16
    • 2017-06-15
    • 1970-01-01
    • 2017-10-23
    相关资源
    最近更新 更多