File: generate_example_images.py

package info (click to toggle)
python-multipletau 0.3.3%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 380 kB
  • sloc: python: 1,557; makefile: 15
file content (33 lines) | stat: -rw-r--r-- 947 bytes parent folder | download | duplicates (4)
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
import os
import os.path as op
import sys

import matplotlib.pylab as plt

thisdir = op.dirname(op.abspath(__file__))
sys.path.insert(0, op.dirname(thisdir))

DPI = 80


if __name__ == "__main__":
    # Do not display example plots
    plt.show = lambda: None
    files = os.listdir(thisdir)
    files = [f for f in files if f.endswith(".py")]
    files = [f for f in files if not f == op.basename(__file__)]
    files = sorted([op.join(thisdir, f) for f in files])

    for f in files:
        fname = f[:-3] + ".jpg"
        if not op.exists(fname):
            exec_str = open(f).read()
            if exec_str.count("plt.show()"):
                exec(exec_str)
                plt.savefig(fname, dpi=DPI)
                print("Image created: '{}'".format(fname))
            else:
                print("No image: '{}'".format(fname))
        else:
            print("Image skipped (already exists): '{}'".format(fname))
        plt.close()