-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
46 lines (33 loc) · 1.19 KB
/
Copy pathplot.py
File metadata and controls
46 lines (33 loc) · 1.19 KB
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
import numpy as np
import matplotlib.pyplot as plt
import subprocess
class Plotter():
def __init__(self,fractal):
self.fractal = fractal
#compile cpp algorithm
def compile_cpp(self,source_file, executable_name):
#compile command
command = ['g++', '-o', executable_name, source_file]
#try to compile
try:
subprocess.run(command, check=True)
print("compilation successful")
except subprocess.CalledProcessError:
print("compilation error")
#run cpp algorithm
def run_cpp(self):
process = subprocess.Popen(['./algorithm'], stdout=subprocess.PIPE)
output = process.communicate()[0]
return np.fromstring(output, sep=' ').reshape((800, 800))
#plot data with matplotlib
def plot_data(self,data):
plt.figure(frameon=False)
plt.imshow(data, cmap='magma', extent=[-2.5, 1.0, -1.0, 1.0], aspect='equal')
plt.subplots_adjust(left=0, right=1, top=1, bottom=0)
plt.axis('off') #
plt.show()
#run methode
def run(self):
self.compile_cpp(self.fractal,'algorithm')
data = self.run_cpp()
self.plot_data(data)