Plotting with Torch7

NVD3 / gfx

Web development provides several vector graphics API. One of them is called D3.js and let users create interactive charts. D3.js is a bit complicated, so NVD3 was created upon it to draw common statistical figures. NVD3 plots are very nice and higly interactive! You can easily plots advanced histograms and scatter plots.
Gfx is a Lua script that start a “tty server” . This server will listen to a folder. Whenever a file is created/modified in this folder, the server send an update to the client.
Eventually, there is a Lua script that will turn torch data into html/javascript. Then , it will create a file on the watched folder.


Pictures can be saved as svg or PNG by a simple click. To my mind, this is the best library.

A few example are provided below

Refresh the page if the charts seem buzzy

You can barely plot everything if you are familiar with jQuery/d3.js.

Some tricks to know:

  • Data are stored in the following folder : ~/.gfx.js/static/data
  • NVD3 API is hidden at this URL : 
  • It is not that complicated to wrap another Javascript API by using the gfx server.
  • The Lua wrapper is a bit slow while using big Tensors. This can become an issue if you want real time plotting abilities.

NB: The current gfx API does not allow to use custom flags. In the meantime, you can use the following file: js.lua. I still have to do a pull request…

3 Comments on “Plotting with Torch7

  1. Great,
    I would like to ask if there is a way how to compute Recall and precision from a confusion matrix and draw them if it is possible. I am facing this problem for more than a month but I could not find an answer. So, please help.

    • Sure!
      First, you can compute your confusion matrix my using the optim package:

      Then, if you want to plot accuracy/recall upon time, Dygraph/Display is a good library

      For every steps:
      – Compute the Precision/Recall from your confusion matrix
      \text{Precision}=\frac{tp}{tp+fp} \,
      \text{Recall}=\frac{tp}{tp+fn} \,

      – Plot it !

      Lua code:

      local labels = {"epoch", 'accuracy', 'recall'}
      local data = {}

      local config =
      title = "Global accuracy/recall upon time",
      labels = labels,
      ylabel = "ratio",

      for t = 1, noEpoch do

      local accuracy, recall = someFct()

      table.insert(data, {t, accuracy, recall })

      -- display = disp.plot(data, config)


      • Hi
        Many thanks for replying but I try it many times but did not work with. Could you please give me more intuition about the code.

Leave a Reply

Your email address will not be published.