XPlot


XPlot - F# Data Visualization Package

XPlot is a cross-platform data visualization package for the F# programming language powered by popular JavaScript charting libraries Google Charts and Plotly. The library provides a complete mapping for the configuration options of the underlying libraries and so you get a nice F# interface that gives you access to the full power of Google Charts and Plotly. The XPlot library can be used interactively from F# Interactive, but charts can equally easy be embedded in F# applications and in HTML reports.

The next two demos show some of the more complex and advanced charts that can be created using XPlot. If you're getting started with XPlot, see the other documentation pages for simpler charts.

Google Charts example

The following example uses the Google Charts library to create a combo chart showing coffee production in Bolivia, Ecuador and Madagascar (as bar plots), together with the average visualized as a line chart:

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
let series = [ "bars"; "bars"; "bars"; "lines" ]
let inputs = [ Bolivia; Ecuador; Madagascar; Average ]

inputs
|> Chart.Combo
|> Chart.WithOptions 
     (Options(title = "Coffee Production", series = 
        [| for typ in series -> Series(typ) |]))
|> Chart.WithLabels 
     ["Bolivia"; "Ecuador"; "Madagascar"; "Average"]
|> Chart.WithLegend true
|> Chart.WithSize (600, 250)

The XPlot library uses the F# |> operator to configure charts. In the above example, we use Chart.Combo to create a basic chart and then we set a number of properties - Chart.WithOptions specifies how the chart looks, Chart.WithLabels and Chart.WithLegend adds the legend that annotates the individual chart series.

Plotly example

The following example uses the Plotly online data analytics and visualization tool. It creates a scatter plot, rendered on a polar chart with different marker color for each of the trials stored in the HobbsPearson data set:

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
let traces =
  [ for trial in HobbsPearson ->
    Scatter(r = trial.Radial, t = trial.Angular, 
      mode = "markers", marker = Marker(color=trial.Color))]

let layout =
  Layout(title = "Hobbs-Pearson Trials", showlegend = false,
    plot_bgcolor = "rgb(223,223,223)")

traces
|> Chart.Plot
|> Chart.WithLayout layout

The code snippet creates one Scatter data series for each of the trials in the input. It sets the r and t properties to two lists of input values. If we wanted to produce an ordinary rectangular scatter plot, we could instead set the x and y properties.

How to get XPlot

XPlot as part of FsLab

If you want to get XPlot as part of larger package of F# and .NET tools for doing data science, then check out the FsLab web site. This gives you a nice cross-platform environment where you can access data using F# Data type providers, analyze the data using Deedle data frames and series and then visualize data using XPlot.

Stand alone XPlot packages

Alternatively, you can reference XPlot via a NuGet package.

Documentation

The documentation for the library is automatically generated from F# script files that you can find in the docs/content folder on GitHub. The links in the right panel point to a number of tutorials that demonstrate some common scenarios. You can also copy the source code from GitHub.

Additionally, the library also comes with an API reference that is generated from code comments. This is work in progress, so please help us & contribute comments and documentation! The most important types are:

  • Google Chart type contains methods for creating charts like Chart.Line and for configuring charts like Chart.WithOptions.

  • Google Options type contains parameters for charts that are specified using Chart.WithOptions.

  • Google Configuration module contains other types that are used as parameters to Chart.WithOptions.

  • Plotly Graph module contains methods for creating various kinds of charts such as Scatter used above.

  • Plotly Layout type specifies common properties of Plotly charts like title and color.

Fork me on GitHub