画图框 [英] Plotting Deedle frame
问题描述
我有以下代码:
let mychart = frame.GetAllSeries() |> Seq.iter(fun key value -> Chart.Line(value, Name=key) |> Chart.Combine
其中,frame.GetAllSeries()
返回seq<KeyValuePair>
.我想将序列直接传递到图表中.
我以为我可以遍历整个序列.问题是我找不到可以直接插入到lambda表达式中的单独访问键和值的方法.
where frame.GetAllSeries()
returns a seq<KeyValuePair>
. I'd like to pipe the sequence directly in a chart.
I thought I could iterate through the sequence. The problem is that I can't find an idomatic way to access the key and value separately that could be plugged in directly in the lambda expression.
谢谢.
编辑
这有效:
let chart = frame.GetAllSeries() |> Seq.map( fun (KeyValue(k,v)) -> Chart.Line(v |> Series.observations, Name=k)) |> Chart.Combine
..它可以变得更简单吗?我的数据集很大,恐怕性能会受到如此多转换的影响.
.. could it get simpler? I have a large dataset and I am afraid the performance gets impacted by so many transformations.
推荐答案
您已经弄清楚,使用Series.observations
可以为您提供一系列的键值对序列,然后您可以将其传递给Chart.Line
等.
As you already figured out, using Series.observations
gives you a sequence of key-value pairs from the series that you can then pass to Chart.Line
etc.
这绝对是不需要的,您可以使用扩展方法使代码更简单,该方法可以自动绘制序列:
This is definitely something that should not be needed and you can make the code simpler using extension method that lets you automatically plot a series:
[<AutoOpen>]
module FsLabExtensions =
type FSharp.Charting.Chart with
static member Line(data:Series<'K, 'V>, ?Name, ?Title, ?Labels, ?Color, ?XTitle, ?YTitle) =
Chart.Line(Series.observations data, ?Name=Name, ?Title=Title, ?Labels=Labels, ?Color=Color, ?XTitle=XTitle, ?YTitle=YTitle)
如果包含此内容,则可以直接绘制序列:
If you include this, you can plot series directly:
let s = series [ for x in 0.0 .. 0.1 .. 1.0 -> x, sin x ]
Chart.Line(s)
您还可以参考Deedle&通过包含这些重载的实验软件包"FsLab"进行F#图表绘制(请参见此处)
You can also reference Deedle & F# Charting through our experimental package "FsLab" that includes these overloads (see here)
这篇关于画图框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!