Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
152 lines (134 sloc) 6.1 KB

About seplot

seplot is a frontend for PyX to create plot from text files in command line or through a python interface. Developed by Serge Dmitrieff.


Installing with pip3 (recommended)

$ pip3 install seplot

Required packages

seplot requires PyX, Numpy, and sio_tools. Pandas is necessary to import csv/excel documents.

$ pip3 install pandas


Basic usage

seplot is meant to be used from command line or from a python script. The typical command line instruction to plot from a file data.txt would be :

$ data.txt

By omitting further instructions, it is implied that the data in data.txt is a set of vertical columns, and we plot column 1 as a function of column 0. seplot uses Python's zero-indexing convention (column 0 is the first column). This could also be written :

$ data.txt mode=v x=0 y=1 out=plot.pdf

Where mode is v (vertical) for columns of data and h for rows (horizontal), and plot.pdf is the output file. Of course several files can be plotted with different colors :

$ data_1.txt color=red data_2.txt color=blue

We can also plot several columns from the same file, use columns for errorbars dx and dy, and plot a function :

$ data_1.txt x=0 dx=1 y=2 dy=3 color=4 size=5 function='y(x)=x'

Here, we even used data to assign a size and color to the plot symbols ! Note that seplot can easily be used from inside a python script :

import seplot
# alternatively, with A an array containing the data

This readme focuses on the command-line interface, but all instructions can also be used equally easily through the python interface.


$ data.txt x=0 y=1 dy=2 and x=0 y=1 line=1

Does a scatter plot of the second column as a function of the first, using the third column for error bars. Then does a line plot of the secund column as a function of the first.

$ data.txt -hist x=10 y=0 data.txt -hist x='[0,1,2,3,4]' y=0

Does a histogram of the first column (y=0) of data.txt, with 10 bins (x=10) and then with bins centered around 0,1,2,3,4.

Data manipulation and conditional expressions

Using Python's eval() function, we can perform operations on the input data. Data read from the data file (eg. data.txt) is stored in a numpy array called A. We can apply any numpy function on A in seplot through a simple syntax :

$ data.txt y='A[:,1]^2'

Here A[:,1] is the second column of A. We can use the same syntax for conditional expressions using the keyword if :

$ data.txt y='A[:,1]^2' if='y>0'

We can now combine several features :

$ data.txt y='A[:,1]^2' if='y>0' color=blue
		   and if='y<0' color=red

We used the and keyword to re-use the data from data.txt into another plot element (note that the shorthand andif=... is also supported).

We can easily compute and plot complex functions of the input data :

$ data.txt y='sqrt(1/(1+A[:,1]^2))/A[:,2]+sin(A[:,3])'

Similarly, the if keyword can be used for any function of the input data :

$ data.txt y='A[:,1]^2' if='sqrt(A[:,1])>10'

Additionally, one can select a sub-set of the data, both by first choosing a range of lines (resp. columns in horizontal mode), and second a conditional expression, e.g. :

$ data.txt range='0:10' if='A[:,1]>0'

Here data from the first 10 lines (lines 0-9 according to Python's numbering convention) if the value of the second columns (A[:,1]) is larger than 0.

Styles and propagation

seplot allows for a wide variety of symbol and line styles and attributes. Some have shorthands, but any style from PyX can be used. For instance let us plot the same data as red dots, a blue solid line, and a thick black dashed line.

$ data.txt color=red style=o and color=blue style=_ and color=black style=-- line=4

Other symbols include "+" (vertical cross), "x" (cross), ">" or "<" (triangle), but any of PyX's can be used.

When using color-by-value, any of PyX's gradients can be used, and some have shorthands :

$ data.txt color=2 gradient=jet and gradient=gray

To keep the same style between two files, and change style for another file, we can use the -keep and -discard keywords :

$ data_0.txt color=red -keep 'data_1.txt' -discard 'data_2.txt'

Note than -keep and -discard keep or discard any option, including y=, range=, if= , etc.

Labels and titles

One of the main interest on using PyX as a backend is to have full LaTeX compatibility. Therefore we can happily write :

$ data.txt xlabel='time ($s$)' ylabel='$v$ ($m s^{-1}$)'

seplot also can read directly the label from a text file using the keyword -autolabel. For example for a file with a simple header # time position}:

$ cat data.txt
	# time position
	0 1
	1 2
	2 3
	3 4

We can use the instruction :

$ data.txt -autolabel

Which will yield xlabel=time and ylabel=position.

We can also specify the position of the graph legend, e.g. with key=tl for the top left :

$ data.txt -autolabel key=tl

Calling seplot from Python

Calling seplot from a Python script offers many possibility, including appending progressively plots during analysis, etc.

import seplot
for i,A in enumerate(list_of_data):
		# A is an element of list_of_data
		# i is its index

Global options are passed when calling seplot.Splotter and local options are passed when calling plot.add_plot, following the same syntax as the command line. One exception, if= (from command line) becomes cond= to avoid confusion.

import seplot
You can’t perform that action at this time.