为什么标记没有出现在我用plotly 创建的图表中?

问题描述 投票:0回答:0

我创建了“线条+标记”模式的图表,在其中绘制我的预测和真实标签。我还想添加一个标记来表示模型的样本外预测,并且应将其放置在 x 轴的末尾。然而,该标记没有出现在图表中。

我的代码如下:

`

fig = go.Figure()

fig.add_trace(go.Scatter(x = index_array, y = targets.flatten(), mode = 'lines + markers',
                        name = 'targets'))

fig.add_trace(go.Scatter(x = index_array, y = predictions.flatten(), mode = 'lines + markers',
                        name = 'predictions'))

fig.add_trace(go.Scatter(x = [index_array[-1]], y = [prediction_out_of_sample], mode = 'markers', marker = dict(size = 12), 
                         name = 'out of sample prediction'))

fig.show()
`

prediction_out_of_sample 是一个实数。

使用此代码生成的图如下:

the plot

如您所见,prediction_out_of_sample 不会作为标记出现在绘图上。

您能解释一下原因并提供解决方案吗?

为了您的方便,我提供了代码。

python-3.x plotly scatter-plot
© www.soinside.com 2019 - 2024. All rights reserved.