为什么不显示XPlot图表?

时间:2018-11-28 16:07:27

标签: f# jupyter-notebook

我正在尝试按照其中一本教程来绘制一些地理图表,但是我没有得到图表,而是得到了XPlot.GoogleCharts.GoogleChart。我在本地主机上使用jupyter笔记本,因此#load正在从计算机中添加模块。

单元格1:

#load "/home/<name>/Downloads/IfSharp.v3.0.1/XPlot.Plotly.Paket.fsx"
#load "/home/<name>/Downloads/IfSharp.v3.0.1/XPlot.Plotly.fsx"

单元2:

Paket.Package ["FsLab"]
#load "/home/<name>/Downloads/IfSharp.v3.0.1/Paket.Generated.Refs.fsx"

单元3:

open System
open FSharp.Data
open XPlot.GoogleCharts

单元格4:

let wb = WorldBankData.GetDataContext()

单元格5:

let emissions =
 [ for c in wb.Countries do
   let v = c.Indicators.``CO2 emissions (kt)``.[2010]
   if not(Double.IsNaN(v)) then yield c.Name, v ]

单元格6:

Chart.Geo(emissions)
|> Chart.WithLabels ["Name"; "Emissions (total kt)"]
|> Chart.WithOptions
    (Options(colorAxis=ColorAxis(colors= [|"#6CC627"; "#DB9B3B"; "#DB7532"; "#DD5321"; "#DB321C"; "#E00B00"; |] )))

enter image description here

1 个答案:

答案 0 :(得分:0)

您的代码可能缺少#load尝试添加的代码:

#load "XPlot.GoogleCharts.fsx"

我还对您的代码做了一些更改,以解决温度遗失的问题:

let getTomorrowTemp place =
  try 
    let w = Weather.Load(forecastUrl + place)
    let tomorrow = Seq.head w.List
    let temp = tomorrow.Temp.Max
    printfn "Getting temperature in: %s %A" place temp
    (place, temp)
    |> Some
  with _ -> None

let worldTemps =
  [ for c in wb.Countries do
      let place = c.Name
      match getTomorrowTemp place with
      | Some v -> yield v
      | None   -> ()
    ]