How to plot to multiple windows in Gnuplot

On my Ubuntu, Gnuplot plots into a Qt window (terminal type qt) by default. Every invocation of the plot command redraws the contents of this single Qt window.

Sometimes, I need to plot two different data sets in two different windows, so that I can compare them side-by-side. To do this specify a window number, an integer starting from 0.

For example:

set terminal qt 0
plot("data_0.txt")

set terminal qt 1
plot("data_1.txt")

Tried with: Gnuplot 5.0 and Ubuntu 14.04

How to output to PDF in Gnuplot

Gnuplot is a great tool for quickly plotting data from a file and viewing it in a window:

plot("sales_data.txt")

To write or print this plot to a PDF file, set the pdf terminal, specify the output filename and plot again:

set terminal pdf
set output "sales_data.pdf"
plot("sales_data.txt")

Tried with: Gnuplot 5.0 and Ubuntu 14.04

How to use Caca terminal of Gnuplot

Plot drawn using caca terminal of GNUPlot
Plot drawn using caca terminal of GNUPlot

Gnuplot can plot in ASCII at the terminal if the dumb terminal is chosen. However, this does not fully utilize the Unicode characters and color support of modern terminals. The Caca terminal of Gnuplot uses all the character and color capabilities of your terminal to generate beautiful and colorful plots. It does this by using the Caca library which provides these capabilities.

Build or Install

Gnuplot can be installed easily:

$ sudo apt install gnuplot

Note that support for caca terminal was added in Gnuplot 4.7. If you have that version and it was built with support for caca, then the commands in the next section should work directly.

If you do not have 4.7 and later and if it was not built with caca support, you need to build Gnuplot from source. Here are the steps I followed to build it from source:

  • Download Gnuplot source code from here and unzip it to a directory.

  • Install the Caca library if you do not have it already:

$ sudo apt install libcaca-dev
  • While building Gnuplot, I got an error in source files that use WxWidgets. To fix that, I opened the configure file, looked for the WX_CXXFLAGS option and appended -std=c++11 to its string.

  • While building Gnuplot, I got an error about linking with a X11 library. To fix that, I opened the configure file, looked for the WX_LIBS option and appended -lX11 to its string.

  • We are now ready to configure and build. Remember to configure with support for caca, since it is still an experimental feature and not enabled by default:

$ ./configure --with-caca
$ make
  • If the build is successful, you can install Gnuplot:
$ sudo make install

Usage

  • To use the caca terminal in Gnuplot:
gnuplot> set terminal caca

You can now plot anything and Caca draws it using ASCII/Unicode characters and colors.

  • You will notice that Caca opens a X window to draw the plot. If you would like it draw the plot in the terminal itself, then you need request caca to use a driver that can draw at the terminal.

  • You can view the list of drivers supported by caca:

gnuplot> set terminal caca driver list
  • Of these, the ncurses and slang drivers can draw to terminal. I found that using slang draws in color, but it shows lots of question mark symbols. So, I use ncurses:
gnuplot> set terminal caca driver ncurses

Now plot anything and view it in beautiful ASCII/Unicode and colors at the terminal!

  • You can find an extensive list of plots drawn using Caca here.

Tried with: Gnuplot 5.0.0, Caca 0.99.beta18 and Ubuntu 14.04

How to check colors supported by terminal

Problem

On the surface it seems like a simple question: how many colors are supported by a terminal you are using? This is important when configuring or debugging color problems in terminal programs like Vim.

Solution 1

The answer should be simple: just query the terminfo database. The easiest way to query the terminfo database to find this out is:

$ tput colors

The problem? The answer reported by this program is wrong! Under a GNOME Terminal which I can see rendering 256 colors, this reports 8 as the answer!

Why is it reporting the wrong answer? It seems to be misled by the TERM environment variable. For reasons which only the Ubuntu/GNOME Gods can answer, the TERM for GNOME Terminal is set to xterm instead of xterm-256color. If you set this manually to xterm-256color, then tput reports 256 correctly. But then what is the point of that?

Solution 2

Left: terminalcolors.py reporting 8 colors for xterm Right: For xterm-256color
Left: terminalcolors.py reporting 8 colors for xterm Right: For xterm-256color

Another solution is to run the terminalcolors.py Python script from here. This beautifully renders the colors in the shell. However, it also falls for the TERM. Only if it is set to xterm-256color can I see 256 colors rendered. Else only the first 8 colors are shown and the rest are in grey.

A similar output and behavior is seen by running msgcat --color=test.

Solution 3

xterm-color-count reporting colors correctly (well almost)
xterm-color-count reporting colors correctly (well almost)

The final solution that worked for me was xterm-color-count. This Bash script actually tries all the XTerm Control Sequences and examines their responses to report the colors. This script was the only one which reported back 256 correctly for me for xterm.

Tried with: GNOME Terminal 3.6.2 and Ubuntu 14.04

How to find resolution of terminal

A terminal or console in Linux is a rectangle which displays a certain number of lines and columns of text. This is the resolution I refer to when I talk about terminal or console. This is not the display resolution, which is expressed in units of pixels.

To find the width or the number of columns: tput cols
To find the height or the number of lines: tput lines

Tried with: Ubuntu 14.04

Terminator

Terminator
Terminator

There are lots of terminal applications for Linux. Most of them now support tabs. However, I was looking for the best terminal application that supported splitting. I think I found it in Terminator.

Install

Installing Terminator is easy:

$ sudo apt-get install terminator

If you are on an old Ubuntu version or need the latest version of Terminator, use the PPA:

$ sudo add-apt-repository ppa:gnome-terminator/ppa
$ sudo apt-get update
$ sudo apt install terminator

Use

When you open Terminator, it opens with one terminal. It has no menubar or toolbar. Many of the operations you can perform can be accessed by right-clicking in the terminal to get a context menu. Terminator has sensible keyboard shortcuts to achieve almost anything you want: split terminal, move between terminals and many other common operations. The split terminal windows can be easily resized by dragging the window border with the mouse.

Some of the keyboard shortcuts I like to use are:

  • Split horizontally: Ctrl + Shift + O

  • Split vertically: Ctrl + Shift + E

  • Switch between split terminals: Ctrl + Tab

  • Move to split terminal above, below, left or right: Alt + Up, Alt + Down, Alt + Left, Alt + Right

  • Show or hide scrollbar: Ctrl + Shift + S

  • Maximize split terminal and resize it back: Ctrl + Shift + X

  • Go fullscreen and back: F11

  • Page up or down: Shift + Pg Up and Shift + Pg Down

  • Search text in the terminal session: Ctrl + Shift + F

Tried with: Terminator 0.97 and Ubuntu 14.04

How to install and use vim-powerline plugin for Vim

Statusline displayed by vim-powerline
Statusline displayed by vim-powerline

The statusline in Vim gets the job done: it shows the current mode and the location of the cursor in the currently open file. The vim-powerline plugin is a great way to jazz up the statusline of Vim and show lots of useful additional information. (As of this writing, folks are working on a new powerline plugin. This post is about the older vim-powerline plugin.)

Installation

The powerline plugin can be installed for Pathogen by cloning its Github repository.

Color support

The plugin uses lots of bright colors and needs 256-color support in Vim. One way to turn this on in Vim is by adding this line to your vimrc:

set t_Co=256

Fancy symbols

By default it shows a simple colored statusline. By using Unicode symbols, it can present a more beautiful statusline. To turn this on, add this line to your vimrc:

let g:Powerline_symbols = "fancy"

Patched fonts

The plugin can show symbols if the file is in version control (Git or Mercurial), for the filetype, for the line number and many more. For this to work, you need to patch your font and use that patched font for your terminal or Vim.

If you are on Ubuntu and using the default Ubuntu Mono font, then a patched version of this font can be obtained here. Follow the instructions on that page to install the fonts.

If you are on Windows and using Consolas, either directly or through SSH with PuTTY, I have more information in another post.

For other fonts and setups, use the script and directions in the fontpatcher directory.

Additional plugins

The plugin can show information on syntax errors and also version control information for Git and Mercurial. To view these status symbols and messages, install these three plugins: syntastic (for syntax checking), fugitive (for Git) and hgrev (for Mercurial).

With all this set up correctly, you get a Vim statusline that looks gorgeous and shows lots of useful information, both in terminal and GUI modes.

Tried with: Vim 7.3 and Ubuntu 12.04 LTS

How to zoom in the terminal of Ubuntu

Zooming in and out in the terminal of Ubuntu is easy and convenient. Zoom here means the font used is increased or decreased in size. Programs like Vim work transparently on zoom, adapting to the new zoom by showing more or less lines of text. This can be a good trick to zoom out to get a good view of the code in Vim before zooming in on the details.

The default keyboard shortcuts to zoom in and out are straightforward: Ctrl and plus keys and Ctrl and minus keys. Note that you need to press the Shift key too to get the minus.

Tried with: Ubuntu 12.04 LTS

How to enable use of mouse in terminal Vim

The mouse can be used naturally in GVim. But, it would be useful to have some mouse functionality in Vim, running in terminal mode too. For example, to scroll the code or to change the size of split windows. This is a nice feature to have, almost all the time we are using the terminal inside a windowing system anyway.

Thankfully, Vim has functionality built-in to use the mouse in terminal mode. The mouse can be enabled by putting this line in your vimrc file:

set mouse=a

Tried with: Vim 7.3