Search code examples
computer-visiongnuplottorch

Bug in torch7 gnuplot package? (ubuntu 16.04)


It seems that gnuplot is rounding all floating values to ints. When plotting lines or surfaces, e.g with these two lines from the documentation

x=torch.linspace(-2*math.pi,2*math.pi)
gnuplot.plot(torch.sin(x))

I obtain enter image description here

instead of enter image description here

As expected, print(torch.sin(x):type()) says that the tensor is indeed a torch.FloatTensor, so I don't understand where that rounding can be happening.

I tried the latest torch7 version and installed gnuplot using luarocks, but the results were the same. I don't think the problem is gnuplot itself, since for example, I can use it from octave without any problems.


Solution

  • I finally found out what the problem was. The locale that was used by default was French, thus floating point numbers were expressed using commas instead of points (e.g. 1,2 instead of 1.2). It appears that this caused Gnuplot to truncate the numbers (it discarded everything after the comma). So, the solution is just

    os.setlocale('C')