YouPlot: preview data immediately in terminal

Sometimes a series of data is generated on a remote server when carrying out calculations, and you want to see a quick preview without heavy post-processing and pretty plotting. YouPlot is just that amazing tool to plot common graphs in the terminal.

Installation

It can be installed via brew, conda, or gem. On Hoffman2, I would suggest using gem, as the conda installation requires ruby and compilers to be installed, which can be heavy.

1
2
module load ruby
gem install --user-install -n~/bin youplot

The first command loads the ruby module, and the second command installs YouPlot locally into your home directory. The -n~/bin option installs the executable into ~/bin, which should be added into the PATH.

Example usage

Line and lines plot

YouPlot takes .tsv or .csv files or any other text with similar format, that is a table with columns separated by specific delimiters. For example, we generate a simple data file of a sine function using python:

sine.py
1
2
3
4
import numpy as np
x = np.linspace(0, 2*np.pi, 100)
y = np.sin(x)
np.savetxt('sine.csv', np.column_stack([x, y]), delimiter=',', header='x,sin(x)', comments='')

After running the above code, the following data is generated in sine.csv:

sine.csv
1
2
3
4
5
6
7
8
9
10
x,sin(x)
0.000000000000000000e+00,0.000000000000000000e+00
6.346651825433925753e-02,6.342391965656450636e-02
1.269330365086785151e-01,1.265924535737492640e-01
1.903995547630177865e-01,1.892512443604102146e-01
2.538660730173570301e-01,2.511479871810792242e-01
3.173325912716962738e-01,3.120334456984870664e-01
3.807991095260355729e-01,3.716624556603275731e-01
4.442656277803748166e-01,4.297949120891716435e-01
...

We then use YouPlot to plot:

1
uplot line -H -d ',' sine.csv

The command line specifies that we want to do a line plot. The -H option specifies that the first row is the header, and -d specifies the delimiter. The default delimiter is a tab, so this option is not needed for .tsv files.

The result is beautiful:

Multiple plots at the same time are also possible:

sine2.py
1
2
3
4
5
import numpy as np
x = np.linspace(0, 2*np.pi, 100)
y1 = np.sin(x)
y2 = np.sin(2*x)
np.savetxt('sine2.csv', np.column_stack([x, y1, y2]), delimiter=',', header='x,sin(x),sin(2x)', comments='')

And then:

1
uplot lines -H -d ',' sine2.csv --ylim -1.1,1.1 --xlim 0,6.28

Be attention that here the command is lines instead of line, due to that multiple lines will be plotted.

Scatter plot

Now we show a more sophisticated example, a scatter plot of the phonon scattering time, generated by ALAMODE (see the previous post). We store the logarithm of the phonon scattering time in scatt_time.csv:

scatt_time.csv
1
2
3
4
5
6
7
8
9
10
11
omega,log10(scatt_time)
2.067062720417716193e+01,-inf
2.067062720417716193e+01,-inf
2.067062720417716193e+01,-inf
9.583115021715137500e+13,-1.177553068581844364e+01
9.583115021715137500e+13,-1.181167514685308184e+01
9.583115021715137500e+13,-1.159247470365145816e+01
2.647641806493650879e+12,-8.397289543264733425e+00
2.647641806493650879e+12,-8.500013594171113240e+00
5.039125836348970703e+12,-8.637881776748896456e+00
...

Here the inf data is due to the 0 value of the scattering time for the \(\Gamma\) point. We use the following command to plot the data:

1
uplot scatter -H -d ',' scatt_time.csv --xlim 0,1e14 --ylim -12.5,-8 --width 100 --height 30

The result is awesome:

References