绘制散点图时的错误

时间:2020-10-01 22:31:21

标签: python python-3.x plotly plotly-python

# Add data
Weeks = df['week_starting']

rates = df['amount']


# Create and style traces
trace0 = go.Scatter(
    x = Weeks,
    y = rates,
    name = 'name',
    line = dict(
        color = ('rgb(255, 3, 57)'),
        width = 4)
)
data = [trace0]

# Edit the layout
layout = dict(title = '$ By Actual Week',
              xaxis = dict(title = 'Weekly Progession'),
              yaxis = dict(title = '$'),
        tickfont=dict(
            color=('rgb(8,48,107)')
     ))
              
fig = dict(data=data, layout=layout)
                            
iplot(fig)

当我尝试运行以上代码时,出现错误,指向iplot(fig) 当我有第二个y轴之前的代码使用im时,它可以在下面工作,当像上面一样删除它时,出现错误,是否涉及到布局时删除了太多代码?

# Add data
Weeks = df['week_starting']

rates = df['amount']


# Create and style traces
trace0 = go.Scatter(
    x = Weeks,
    y = rates,
    name = 'name',
    line = dict(
        color = ('rgb(255, 3, 57)'),
        width = 4)
)
data = [trace0]

# Edit the layout
layout = dict(title = '$ By Actual Week',
              xaxis = dict(title = 'Weekly Progession'),
              yaxis = dict(title = '$'),
              yaxis2 = dict(title=' Minutes',
              overlaying='y',
        side='right',
        titlefont=dict(
            color= ('rgb(8,48,107)'),
        ),
        tickfont=dict(
            color=('rgb(8,48,107)')
     )))
              
fig = dict(data=data, layout=layout)
                            
iplot(fig)

此代码可以运行,但是当我移除第二个y轴时,第一个代码不会运行,谢谢!

0 个答案:

没有答案