# Plotting with Torch7

**Gnuplot-wrappers**

Gnuplot is a cross-platform command-line oriented graphing application. It can plot everything : 2D, 3D pictures. The API exist since 1986, thus it is kind of robust! Lua Wrappers are good and easy to use for most of basic figures. However, advanced features requires to be familiar with gnuplot interface. Charts can be saved in a large range of format from png to eps. One of the major drawback of Gnuplot is its lack of interactivity. If you are now willing to play with web API, then, it is worth learning the gnuplot command-line options (I wish you good luck :P).

- Lua API : https://github.com/torch/gnuplot
- Underlying API : http://www.gnuplot.info/

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
require("gnuplot") local x = torch.linspace(-2*math.pi,2*math.pi) local y1 = torch.sin(x) local y2 = torch.cos(x):mul(0.5) gnuplot.figure(1) gnuplot.xlabel('Time ms()') gnuplot.ylabel('') gnuplot.title('Gnuplot example') gnuplot.plot( {'Sinus Wave' , x, y1,'~'}, {'Cosinus Wave', x, y2,'~'} ) |

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
require("gnuplot") local x1 = torch.randn(40):mul(100) local y1 = torch.randn(40):mul(100) local x2 = torch.randn(40):mul(100) local y2 = torch.randn(40):mul(100) local x3 = torch.randn(40):mul(100) local y3 = torch.randn(40):mul(100) gnuplot.figure(1) gnuplot.xlabel('Time ms()') gnuplot.ylabel('') gnuplot.title('Gnuplot example') gnuplot.plot( {'Group1' , x1, y1,'+'}, {'Group2' , x2, y2,'+'}, {'Group3' , x3, y3,'+'} ) |

Some tricks to know:

- $> killall gnuplot_x11 will be your best friend
- The method
*gnuplot.imagesc is*very useful to plot activation units over mini-batch. It is hard to implement it

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: https://github.com/torch/optim/blob/master/ConfusionMatrix.lua

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

--computation

local accuracy, recall = someFct()

--storage

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

-- display

config.win = disp.plot(data, config)

`end`

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.

Regards,