File: plot_csv.py

package info (click to toggle)
roc-toolkit 0.4.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 9,684 kB
  • sloc: cpp: 102,987; ansic: 8,959; python: 6,125; sh: 942; makefile: 16; javascript: 9
file content (38 lines) | stat: -rwxr-xr-x 797 bytes parent folder | download
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
#!/usr/bin/env python3

import fileinput
import numpy
import pylab
import sys

text = []
columns = []

for line in fileinput.input(encoding='utf-8'):
    line = line.strip()
    if line.startswith('#'):
        columns = line.replace('#', '').split(',')
        continue
    text.append(line)

data = numpy.genfromtxt(text, dtype=float, delimiter=',')

if len(data.shape) == 1:
    data = data[:,numpy.newaxis]

if not columns:
    columns = [None] * data.shape[1]

fig, axs = pylab.subplots(len(columns), 1, sharex=True)

if len(columns) == 1:
    axs = [axs]

for col_idx, col_name in enumerate(columns):
    axs[col_idx].ticklabel_format(style='plain')
    if col_name:
        axs[col_idx].set_title(col_name)
    axs[col_idx].grid()
    axs[col_idx].plot(data[:,col_idx], '-*')

pylab.show()