FnuPlot


Lightweight F# wrapper for gnuplot

FnuPlot is a lightweight wrapper for the gnuplot charting and visualization library, which lets you create cross-platform, publication-quality charts on Mac, Linux and Windows. FnuPlot provides two features on top of gnuplot:

  • First, it hides the gnuplot process, so you do not have to start and control the process. You can easily starts gnuplot in the background just by creating a new instance of the GnuPlot type. Then you can send commands to gnuplot easily using the SendCommand method.

  • Second, FnuPlot implements a simple domain-specific language for building a number of common chart types. This means that you can use gp.Plot to plot charts for functions, line charts, histograms and a few other charts and you can use gp.Set to configure gnuplot.

Visualizing population of the world

To give see a quick example of the DSL for building gnuplot charts, have a look at the following example from the [visualizing population using WorldBank data] tutorial. The tutorial downloads data from the WorldBank and then uses FnuPlot to create a single chart combining three histograms for three different years:

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
12: 
13: 
14: 
15: 
16: 
17: 
// Starts 'gnuplot' process interactively
#r "FnuPlot.dll"
open FnuPlot
let gp = new GnuPlot()

// Configure chart style, ranges and titles
gp.Set
  ( style = Style(Solid), 
    range = RangeY.[ 5e8 .. 75e8 ],
    titles = Titles(x = names, xrotate = -90) )

// Create a chart combining several histograms
[ for year, values, color in stats ->
    Series.Histogram
      ( data = values, title = string year, 
        lineColor = color) ]
|> gp.Plot

The example first creates GnuPlot (assuming that the executable is in your PATH). Then it calls gp.Set to configure the chart, setting the Y axis range and titles. Then it creates a sequence of histograms (with different line colours) that are then passed to gp.Plot to display the plot. The resulting chart looks as follows:

WorldBank data visualization

How to get FnuPlot

  • The library is available as FnuPlot on NuGet. To get the code also, get the code from GitHub.

  • All of the FnuPlot functionality is currently implemented in a single file, and so you can also copy the FnuPlot.fs file to your project. The recommended way to do this is to use Paket for managing your references and use GitHub reference specified in your paket.dependencies file using github fsprojects/FnuPlot src/FnuPlot/FnuPlot.fs.

Samples & documentation

The FnuPlot library comes with a documentation that is automatically generated from *.fsx files in the content folder. This means that you can also open the code in your favourite F# editor and run it interactively.

  • Read the Getting started tutorial, which contains more detailed description of different charts supported by the library. The Visualizing population using WorldBank tutorial shows how to create the chart above.

  • API Reference contains automatically generated documentation for all types, modules and functions in the library. This includes additional brief samples on using most of the functions.

Contributing and copyright

The project is hosted on GitHub where you can report issues, fork the project and submit pull requests. If you're adding a new public API, please also consider adding samples that can be turned into a documentation.

The library is available under Apache 2.0 license, which allows modification and redistribution for both commercial and non-commercial purposes. For more information see the License file in the GitHub repository.

val names : 'a list

Full name: Index.names
val stats : 'a list

Full name: Index.stats
namespace FnuPlot
val gp : GnuPlot

Full name: Index.gp
Multiple items
type GnuPlot =
  interface IDisposable
  new : ?path:string -> GnuPlot
  private new : actualPath:string -> GnuPlot
  member private Dispose : disposing:bool -> unit
  override Finalize : unit -> unit
  member Plot : data:seq<Series> * ?style:Style * ?range:Range * ?output:Output * ?titles:Titles -> unit
  member Plot : data:Series * ?style:Style * ?range:Range * ?output:Output * ?titles:Titles -> unit
  member Plot : func:string * ?style:Style * ?range:Range * ?output:Output * ?titles:Titles -> unit
  member SendCommand : str:string -> unit
  member Set : ?style:Style * ?range:Range * ?output:Output * ?titles:Titles * ?TimeFormatX:TimeFormatX -> unit
  ...

Full name: FnuPlot.GnuPlot

--------------------
new : ?path:string -> GnuPlot
member GnuPlot.Set : ?style:Style * ?range:Internal.Range * ?output:Output * ?titles:Titles * ?TimeFormatX:TimeFormatX -> unit
Multiple items
type Style =
  interface ICommand
  new : ?fill:FillStyle -> Style

Full name: FnuPlot.Style

--------------------
new : ?fill:FillStyle -> Style
union case FillStyle.Solid: FillStyle
val RangeY : Internal.RangeImplY

Full name: FnuPlot.Ranges.RangeY
Multiple items
type Titles =
  interface ICommand
  new : ?x:string list * ?xrotate:int * ?y:string list * ?yrotate:int -> Titles

Full name: FnuPlot.Titles

--------------------
new : ?x:string list * ?xrotate:int * ?y:string list * ?yrotate:int -> Titles
argument x : string list option
val year : obj
val values : seq<float>
val color : System.Drawing.Color
Multiple items
type Series =
  new : plot:SeriesType * data:Data * ?title:string * ?lineColor:Color * ?weight:int * ?fill:FillStyle -> Series
  member Command : string
  member Data : Data
  static member Histogram : data:seq<float> * ?title:string * ?lineColor:Color * ?weight:int * ?fill:FillStyle -> Series
  static member Impulses : data:seq<DateTime * float> * ?title:string * ?lineColor:Color * ?weight:int -> Series
  static member Impulses : data:string * ?title:string * ?lineColor:Color * ?weight:int -> Series
  static member Impulses : data:seq<float * float> * ?title:string * ?lineColor:Color * ?weight:int -> Series
  static member Impulses : data:seq<float> * ?title:string * ?lineColor:Color * ?weight:int -> Series
  static member Lines : data:seq<DateTime * float> * ?title:string * ?lineColor:Color * ?weight:int -> Series
  static member Lines : data:string * ?title:string * ?lineColor:Color * ?weight:int -> Series
  ...

Full name: FnuPlot.Series

--------------------
new : plot:SeriesType * data:Data * ?title:string * ?lineColor:System.Drawing.Color * ?weight:int * ?fill:FillStyle -> Series
static member Series.Histogram : data:seq<float> * ?title:string * ?lineColor:System.Drawing.Color * ?weight:int * ?fill:FillStyle -> Series
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = System.String

Full name: Microsoft.FSharp.Core.string
member GnuPlot.Plot : data:seq<Series> * ?style:Style * ?range:Internal.Range * ?output:Output * ?titles:Titles -> unit
member GnuPlot.Plot : data:Series * ?style:Style * ?range:Internal.Range * ?output:Output * ?titles:Titles -> unit
member GnuPlot.Plot : func:string * ?style:Style * ?range:Internal.Range * ?output:Output * ?titles:Titles -> unit
Fork me on GitHub