6

I'm searching for a command line tool (for linux) to generate plots out of a data file. I tried to play with gnuplot at first but it's curve fitting capabilities aren't that good.

Then I tried R but I couldn't find a way to write a vector (little arrow over the sign) or a thermal average (\left \langle \right \rangle in LaTeX).

I there some hidden plugin for any of those I couldn't find to complete the task?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Yotam
  • 10,295
  • 30
  • 88
  • 128

7 Answers7

5

Here's one way you could make one. Input files should be formatted with one or more columns of data. If there are two or more columns, the first column is used as the X in an X,Y plot.

#! /usr/bin/env python

import sys
import matplotlib.pyplot as pyplot

for filename in sys.argv[1:]:
   with open(filename,'rt') as sf:
      table = []
      for line in sf: table.append( [float(val) for val in line.split()] )
      table = [ row for row in table if len(row) ] ## remove empty rows
      if len(table[0]) == 1 : pyplot.plot( [y[0] for y in table ] )
      for x in xrange(1,len(table[0])): pyplot.plot( [ y[0] for y in table ], [ y[x] for y in table ] )
pyplot.show()
Brent Bradburn
  • 51,587
  • 17
  • 154
  • 173
  • 1
    matplotlib is my absolute favourite. It's incredibly powerful and if it doesn't do something the way you want it to, it's also hackable. – Michael Wild Feb 13 '13 at 07:53
  • Some similar, but more concise, examples: http://stackoverflow.com/questions/11248812/matplotlib-basic-plotting-from-text-file, http://stackoverflow.com/questions/12311767/how-to-plot-files-with-numpy – Brent Bradburn Feb 23 '13 at 00:00
  • Hi, this question was just upvoated and I came here to read the answers, I ended up using python. So, you are marked as my answer. Thanks. – Yotam Apr 23 '14 at 12:08
  • If you have a CSV, you can specify a delimiter: `split(",")`. You may also need to read an initial row of column headers: `headers = sf.readline().split(",")` – Brent Bradburn Oct 08 '19 at 20:00
1

Is there a command-line tool

I am interpreting this to mean that you want to create the plot directly from the linux (e.g. Bash) command-line without creating a script in some other language.

It appears the the answer is: not really, with one exception: xplot

Like most x* utilities, this has a very "un-modern" UI. But it can generate plots from a simple command-line such as xplot a.txt b.txt.

Brent Bradburn
  • 51,587
  • 17
  • 154
  • 173
1

In the same spirit as xplot, you also have ctioga2 there: http://ctioga2.sf.net. Plotting text data files is as easy as

ctioga2 data.dat

Which generates a Plot-000.pdf PDF file. But then, it does not fit data.

Vincent Fourmond
  • 3,038
  • 1
  • 22
  • 24
1

There are a set of command-line tools (mgl2png, mgl2eps, mgl2svg, ...) which produce the picture with plotting. But them use its own script language MGL (rather simple and fast). It is part of GPL library MathGL.

abalakin
  • 825
  • 7
  • 6
0

Have you tried PGF/TikZ? It can take a while to get used to it, but it has first class LaTeX integration (it is a library for LaTeX, after all), and there are tons of examples on this website.

After you figure out the syntax, you can write a simple script that will convert all data you need in a suitable format.

Take a look at GNUPLOT basics article. It will show you how to call Gnuplot using PGF/TikZ, and afterwards load the results from an external file.

darioo
  • 46,442
  • 10
  • 75
  • 103
0

I'm very much surprised at your assessment that gnuplot is not good at curve fitting. In my experience, gnuplot has no equal for this sort of work. But my experience is admittedly limited so you may know a lot better.

Anyway, I found this and though it might help : http://www.cs.hmc.edu/~vrable/gnuplot/using-gnuplot.html It has a section on curve fitting.

Tom Macdonald
  • 6,433
  • 7
  • 39
  • 59
0

Check out SciPy or Octave.

yasouser
  • 5,113
  • 2
  • 27
  • 41