自动缩放情节`plotly` [英] autoscale the plot `plotly`
本文介绍了自动缩放情节`plotly`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要绘制真实数组和预测数组之间的误差图.我已经设法用 plotly
做到了,如 Code 1
所示,但生成的图在顶部有太多空间.如果我按下图中的 autoscale
按钮 - 它会修复它.
I need to produce a plot of errors between the true and predicted arrays. I've managed to do it with plotly
, as shown in Code 1
, but the produced plot has too much space on the top. If I press the autoscale
button in the plot - it fixes it.
代码 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
按钮)?
Can it be done automatically (i.e.without me needing to press the autoscale
button each time)?
提前致谢.
推荐答案
您可以尝试以下操作:
fig['layout']['yaxis'].update(autorange = True)
这篇关于自动缩放情节`plotly`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文