• Martin Thoma
  • Home
  • Categories
  • Tags
  • Archives
  • Support me

1D Data Visualization

Contents

  • 1D Data Visualization
    • Prerequesites
    • See also

Once in a while I have to visualize simple 1D numerical data. So here is an example script:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Visualize C_0.99 for all languages except the 10 with most characters."""

import matplotlib.pyplot as plt
import seaborn as sns

sns.set_style("whitegrid")


def plot_1d(l, colors=None, xlabel="", ylabel=""):
    """Plot a 1D list l of numbers."""
    ax = sns.barplot([i for i in range(len(l))], l, palette=colors)
    ax.set(xlabel=xlabel, ylabel=ylabel, label="big")
    ax.set_xticks([])

    plt.savefig("example.pdf")
    plt.savefig("example.png")
    plt.show()


if __name__ == "__main__":
    l = [41, 44, 46, 46, 47, 47, 48, 48, 49, 51, 52, 53, 53, 53, 53, 55, 55,
         55, 55, 56, 56, 56, 56, 56, 56, 57, 57, 57, 57, 57, 57, 57, 57, 58,
         58, 58, 58, 59, 59, 59, 59, 59, 59, 59, 59, 60, 60, 60, 60, 60, 60,
         60, 60, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 61, 62, 62, 62, 62,
         62, 62, 62, 62, 62, 63, 63, 63, 63, 63, 63, 63, 63, 63, 64, 64, 64,
         64, 64, 64, 64, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 65, 66,
         66, 66, 66, 66, 66, 66, 67, 67, 67, 67, 67, 67, 67, 67, 68, 68, 68,
         68, 68, 69, 69, 69, 70, 70, 70, 70, 71, 71, 71, 71, 71, 72, 72, 72,
         72, 73, 73, 73, 73, 73, 73, 73, 74, 74, 74, 74, 74, 75, 75, 75, 76,
         77, 77, 78, 78, 79, 79, 79, 79, 80, 80, 80, 80, 81, 81, 81, 81, 83,
         84, 84, 85, 86, 86, 86, 86, 87, 87, 87, 87, 87, 88, 90, 90, 90, 90,
         90, 90, 91, 91, 91, 91, 91, 91, 91, 91, 92, 92, 93, 93, 93, 94, 95,
         95, 96, 98, 98, 99, 100, 102, 104, 105, 107, 108, 109, 110, 110, 113,
         113, 115, 116, 118, 119, 121]
    colors = []
    en_found = False
    for value in l:
        if value == 60 and not en_found:  # eng
            colors.append("red")
            en_found = True
        elif value == 88:  # rus
            colors.append("blue")
        else:
            colors.append("grey")
    plot_1d(l, colors, xlabel="Languages", ylabel="$|C_{99}|$")

which gives

Visualization of 1D numeric data
Visualization of 1D numeric data

Prerequesites

You need to install seaborn.

See also

  • seaborn.barplot
  • seaborn.countplot
  • seaborn.distplot

Published

Sep 3, 2017
by Martin Thoma

Category

Machine Learning

Tags

  • Data Visualization 3
  • Machine Learning 81

Contact

  • Martin Thoma - A blog about Code, the Web and Cyberculture
  • E-mail subscription
  • RSS-Feed
  • Privacy/Datenschutzerklärung
  • Impressum
  • Powered by Pelican. Theme: Elegant by Talha Mansoor