我需要绘制真实数组和预测数组之间的错误图。正如plotly
所示,我已经设法用Code 1
来做到这一点,但是生成的图在顶部有太多的空间。如果我按图中的autoscale
按钮-它会解决问题。
代码1:
import numpy as np
import plotly.graph_objects as go
N = 40
y1 = np.random.randint(0, 2, N)
y2 = np.random.randint(0, 2, N)
err = np.where(y1 != y2)[0]
fig = go.Figure()
fig.add_trace(
go.Scatter(
x=err,
y=np.zeros_like(err),
name='Prediction Errors',
mode='markers',
marker_symbol='x',
marker_color='red',
showlegend=True
)
)
fig.update_layout(title_text = 'Errors in activity prediction', height=10)
fig.update_xaxes(title_text = 'User index', range=[-0.3, N])
fig.update_yaxes(range=[-0.01, 0.1], visible=False)
生成的图像:
所需的输出:
我的问题
可以自动完成吗(也就是说,我不需要每次都按下autoscale
按钮)?
谢谢。
答案 0 :(得分:1)
您可以尝试以下操作:
fig['layout']['yaxis'].update(autorange = True)