首页 > 解决方案 > 在 F# 中使用 xplot/plotly 的连续误差带

问题描述

我正在尝试制作这样的图表:

在此处输入图像描述

如此处页面中所述:https ://plotly.com/python/continuous-error-bars/

相关的python代码是:

go.Scatter(
    x=x+x[::-1], # x, then x reversed
    y=y_upper+y_lower[::-1], # upper, then lower reversed
    fill='toself'
)

但我不太确定如何使 F# 等效于:

y=y_upper+y_lower[::-1]

使用 xplot/plotly

我怎样才能画出这样的图表?

标签: f#plotly

解决方案


实际上,您可以为此使用 Plotly.NET!

这是一个完整的片段,它将在 .NET Interactive 中重现图表。

#r "nuget: Plotly.NET.Interactive, 2.0.0-beta9"

open Plotly.NET

let x = [1; 2; 3; 4; 5; 6; 7; 8; 9; 10]
let y = [1; 2; 7; 4; 5; 6; 7; 8; 9; 10]
let y_upper = [2; 3; 8; 5; 6; 7; 8; 9; 10; 11]
let y_lower = [0; 1; 5; 3; 4; 5; 6; 7; 8; 9]

Chart.Range(
    x,
    y,
    y_upper,
    y_lower,
    StyleParam.Mode.Lines,
    Color="rgb(0,100,80)",
    RangeColor="rgba(0,100,80,0.2)")

文档中的渲染由于某种原因拉伸了 x 轴,即使我在跟踪本身中看不到它。

有关更多信息,请参阅范围图

在此处输入图像描述

至于y=y_upper+y_lower[::-1]位,这只是 F# 中的一个列表追加,所以它是:

y_upper @ (y_upper |> List.rev)

但是,至少在最初,如果您使用 Plotly.NET,这似乎是不必要的。


推荐阅读