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.
Code 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)
Produced image:
Desired output:
My question:
Can it be done automatically (i.e.without me needing to press the autoscale
button each time)?
Thanks in advance.