File: plotBenchmark.py

package info (click to toggle)
yade 2025.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,308 kB
  • sloc: cpp: 93,298; python: 50,409; sh: 577; makefile: 162
file content (27 lines) | stat: -rw-r--r-- 815 bytes parent folder | download | duplicates (2)
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
import matplotlib as mpl

mpl.use('Agg')  # so it runs without a X server (e.g. HPC)

import matplotlib.pyplot as plt
import os

for case in ['Case1', 'Case2', 'Case3']:
	files = [file for file in os.listdir("./outputData") if (file.startswith(case) and file.endswith(".txt"))]
	if len(files) == 0:
		continue  # no data for this case
	for f in files:
		X, Y, titles = [], [], []
		for line in open("./outputData/" + f, 'r'):
			if len(titles) == 0:
				titles = [str(s) for s in line.split()]
				continue
			values = [float(s) for s in line.split()]
			X.append(values[0] if case != 'Case1' else values[-1])
			Y.append(values[1])
		plt.plot(X, Y, label=f)
	plt.xlabel(titles[1 if case != 'Case1' else -1])
	plt.ylabel(titles[2])
	plt.legend()
	print("saving", case, "...")
	plt.savefig(case + '.png')
	plt.clf()