Visualizing Data in the Terminal: A Guide to YouPlot from Red Data Tools

By Group J035

Introduction

YouPlot is a command-line data visualization tool designed for users who prefer working in a terminal environment. It offers a lightweight and efficient way to generate quick visual insights without the need for GUI-based software. Whether you're working with CSV, JSON, or direct input, YouPlot enables the creation of bar charts, line plots, scatter plots, histograms, and more. This makes it an excellent tool for data analysts, developers, and researchers who require an instant graphical representation of data within scripts or interactive sessions.

Installation & Setup

For Windows

To install ruby visit rubyinstaller.org, click on download and follow the following steps:

For MacOs(Terminal)

brew install youplot

For linux(NixOS)(Terminal)

nix shell nixpkgs 

For linux(GNU Guix)

guix install youplot  

For linux(conda)

conda install -c conda-forge ruby
conda install -c conda-forge compilers 
     

Once ruby installed verify by running:

ruby --v
gem --v

To install the tool, use the following command:

gem install youplot

Once installed, to see the version:

uplot --version

Key Features

Basic Commands

Subcommands

Support Commands

Code Examples

General Syntax

The basic syntax for using YouPlot is:

C:\Users\desktop1> uplot <command> [options] <data.tsv>

<command>: Type of plot you want (e.g., bar, line, scatter).
[options]: Customization options for the plot (like color, title, etc.).
<data.tsv>: The input file or data stream.

Bar Plot Example

This command creates a bar plot from inline data using a comma as a delimiter.

C:\Users\desktop1> echo "Category A,10
Category B,25
Category C,18
Category D,30
Category E,22
Category F,15
Category G,28
Category H,35
Category I,40
Category J,50" | uplot bar -d ',' -t "Bar Plot Example"
Density Plot in Red

Explanation: The -d ',' specifies that the delimiter is a comma. The -t option adds a title to the plot.

Histogram Example 1

This command creates a histogram from a set of numerical values with 10 bins.

C:\Users\desktop1> "echo "1`n5`n2`n3`n6`n8`n7`n5`n3`n2`n1`n7`n8`
    n9`n5`n6`n4`n3`n2`n6`n7`n8`n9`n2`n3`
    n4`n5`n6`n7`n8`n9`n10`n12`n15`n18`
    n20`n22`n25`n28`n30`n35`n40`n45`n50`n55`
    n60`n65`n70`n75`n80`n85`n90`n95`n100"
    uplot hist --n 10 -t "Histogram"
Density Plot in Red

Explanation: --nbins 10 divides the data into 10 bins. -t adds a title.

Line Plot Example

This command creates a simple line plot with space-separated values.

C:\Users\desktop1> "-10,100
    -9,81
    -8,64
    -7,49
    -6,36
    -5,25
    -4,16
    -3,9
    -2,4
    -1,1
    0,0
    1,1
    2,4
    3,9
    4,16
    5,25
    6,36
    7,49
    8,64
    9,81
    10,100" | uplot line -d ' ' -t "Line plot of quadratic formula" 
Density Plot in Red

Explanation:

uplot line creates a line plot

The -d ' ' option specifies space as the delimiter.

Scatter Plot Example

This scatter plot visualizes two sets of numerical values separated by spaces.

C:\Users\desktop1> echo "1 3
2 6
3 9
4 12
5 15
4 7
9 5
3 10
7 2
4 8
1 1
5 6
3 7
2 5" | uplot scatter -d ' ' -t "Scatter Plot in Red" -c red
Density Plot in Red

Explanation: Each line contains an (x, y) pair. -c red colors the scatter points red.

Density Plot Example

This command generates a density plot using randomly generated values.

C:\Users\desktop1> python -c "import random; print('\n'.join(f'{random.uniform(0,10)} {random.uniform(0,10)}' for _ in range(150)))" |
uplot density -d ' ' -t "Density Plot"
Density Plot in Red

Explanation: Random (x, y) pairs are generated. The density plot visualizes the distribution of points.

Box Plot Example

This command creates a box plot for two different groups.

C:\Users\desktop1> echo "GroupA 10
GroupA 12
GroupA 14
GroupA 9
GroupB 11
GroupB 20
GroupB 22
GroupB 19
GroupB 23
GroupB 21" | uplot box -d ' ' -t "Box Plot of Two Groups"
Density Plot in Red

Explanation: Shows median, quartiles, and outliers for two groups.

Changing Plot Colors

YouPlot allows color customization using the -c option.

C:\Users\desktop1> echo "GroupA 10
GroupA 12
GroupA 14
GroupA 9
GroupB 11
GroupB 20
GroupB 22
GroupB 19
GroupB 23
GroupB 21" | uplot box -d ' ' -t "Boxplot in Yellow" -c yellow
Density Plot in Red

Explanation: -c yellow changes the box plot color.

Density Plot with Custom Color

This density plot uses red as the color.

C:\Users\desktop1> python -c "import random; print('\n'.join(f'{random.uniform(0,10)} {random.uniform(0,10)}' for _ in range(50)))" |
uplot density -d ' ' -t "Density Plot in Red" -c red
Density Plot in Red

Line Plot with Custom Color

This command creates a simple line plot with space-separated values.

C:\Users\desktop1> echo "1 5
2 15
3 25
4 35
5 45" | uplot line -d ' ' -t "Line Plot in Blue" -c blue
Density Plot in Red

Explanation: The -d ' ' option specifies space as the delimiter. -c blue sets the line color to blue.

Use Cases

YouPlot is a powerful command-line tool that can be combined with other utilities like awk, git bash, curl, python, and cut to visualize data efficiently. Here are some practical applications:

1. Visualizing Data from a Remote Dataset Using curl and cut

$ cat better_iris_data.tsv | head 
Density Plot in Red

(Existing dataset)

$ cut -f1-4 better_iris_data.tsv | uplot boxplot -H -t "Iris Data Distribution"
Density Plot in Red

Explanation:

cut -f1-4 Extracts the first four columns from the dataset

uplot boxplot -H -t Generates a boxplot titled "IRIS DATA Distribution" using the extracted data.

2. Simple Line Plot Using cat

$ echo -e "Value1\tValue2\n1\t5\n2\t10\n3\t15\n4\t20\n5\t25" > data.tsv

Creating a dataset and uploading to a file

Density Plot in Red

Explanation:

cat data.csv reads the contents of the data.tsv file

uplot line -H plots the data as a line graph with headers automatically detected

This is useful for quickly checking trends in your data.

3. Combining Python with YouPlot for Random Data Visualization

$ python -c "import random; print('\n'.join(f'{random.uniform(0,10)} {random.uniform(0,10)}' for _ in range(50)))" |
        uplot density -d ' ' -t "Density Plot in Red" -c red
Density Plot in Red

Explanation:

python generates 50 pairs of random values

uplot density -d ' ' -t Visualizes the random points on a density plot.

This is ideal for testing visualization layouts with randomly generated data.

4. Quick Data Visualization Using echo

$ echo -e "1 10\n2 20\n3 30\n4 40\n5 50" > spaced_data.txt
        uplot bar -d ' ' -t "Bar plot with Space Delimiter" spaced_data.txt
    
Density Plot in Red

Explanation:

echo -e Prints the provided text to the terminal. The -e option allows interpretation of special characters like \n for new lines

1 10\n2 20\n3 30\n4 40\n5 50 This is the data being passed, where each line represents a pair of X and Y values.

uplot bar creates a bar plot

-d ' ' Specifies a space as the delimiter between the two numbers

-t Sets the title of the chart.

This method is useful for visualizing small sets of data quickly without creating a separate file. For example, you can visualize sales data for a week or test simple data inputs.

5. Using AWK with YouPlot

AWK is a powerful command-line tool for pattern scanning and processing. It is commonly used for data extraction and reporting. When combined with YouPlot, it becomes a handy way to preprocess data before visualizing it directly in the terminal.

Horizontal Bar Chart Using AWK

$ awk 'NR>1 {print $1, $2}' data.tsv | uplot bar -d ' '
Density Plot in Red

Explanation:

Line Chart Using AWK

$ awk 'NR>1 {print NR-1, $2, $3}' line_data.tsv | uplot line -d ' '
Density Plot in Red

Explanation:

Scatter Plot Using AWK

$ echo "Scatter Plot (Height vs. Weight):"
$ awk 'NR>1 {print $1, $2}' random_data.tsv | uplot scatter -d ' '
Density Plot in Red

Explanation:

Generates various plots from the extracted data.

Conclusion

YouPlot is a powerful yet simple solution for data visualization in the command line. By eliminating the need for heavyweight applications, it allows users to quickly analyze datasets and extract meaningful insights. Whether for automating data exploration or visualizing real-time data, this tool proves to be a valuable addition to any developer’s workflow. Its compatibility with various data formats and ease of installation make it an excellent choice for anyone seeking an efficient, scriptable, and fast visualization method in the terminal.

References & Further Reading

Authors: Bhavesh, Chinmay, Vasudev