-
Notifications
You must be signed in to change notification settings - Fork 0
/
Python.cpp
122 lines (98 loc) · 3.17 KB
/
Python.cpp
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#include <stdlib.h>
#include <iostream>
#include <ctime>
#include <fstream>
#include <iterator>
#include "Partition.h"
#include "DimVec.h"
#include "DimVecBank.h"
#include "DimVecAnalyser.h"
#include "Python.h"
using namespace std;
void PythonEngine::GetDimVecs(const dim_vec_pred pred) {
clear();
pAnalyser->copy_pred(pred,*this);
}
bool PythonEngine::Python2DInit() {
char filename[8] = "plot.py";
myfile.open(filename, ios::out | ios::trunc);
if(!myfile.is_open())
return false;
myfile << "import matplotlib.pyplot as plt \n";
myfile << "import matplotlib.colors as col \n";
myfile << "fig = plt.figure(figsize = (10,10)) \n";
myfile << "ax = fig.add_subplot(111) \n";
return true;
}
void PythonEngine::Python2D(const int_partition_bank& thePartnBank, const int_partition_layer::vector_of_ptr_bin& dots, char col, char mark)
{
myfile << "X = [] \n";
myfile << "Y = [] \n";
//const int_partition_layer& partnLayer = pAnalyser->GetDimVecLayer().GetPartitionLayer();
for(nat n = 0; n < thePartnBank.size(); ++n)
{
for(int_partition_layer::vector_of_ptr::const_iterator i = dots[n].begin(); i != dots[n].end(); ++i)
{
myfile << "X.append(" << distance(thePartnBank[n].begin(), *i) << ") \n";
myfile << "Y.append(" << (*i)->size() << ") \n";
}
//myfile << "Y.extend([" << n << "]*" << dots[n].size() << ") \n";
}
myfile << "ax.scatter(X,Y) \n";
}
bool PythonEngine::Python3DInit() {
char filename[8] = "plot.py";
myfile.open(filename, ios::out | ios::trunc);
if(!myfile.is_open())
return false;
myfile << "import matplotlib.pyplot as plt \n";
myfile << "import matplotlib.colors as col \n";
myfile << "fig = plt.figure(figsize = (10,10)) \n";
myfile << "ax = fig.add_subplot(111, projection = '3d') \n";
return true;
}
void PythonEngine::PythonAxis(nat idx, char var) {
dim_vec::vector_of_ptr::const_iterator i;
itr_partn arm;
const int_partition_layer& partnLayer = pAnalyser->GetDimVecLayer().GetPartitionLayer();
i = begin();
arm = (*begin())->GetArms()[idx];
myfile << var << ".extend([" << distance(partnLayer.begin(), arm);
for(++i; i != end(); ++i)
{
arm = (*i)->GetArms()[idx];
myfile << ", " << distance(partnLayer.begin(), arm);
}
myfile << "]) \n";
}
void PythonEngine::Python3D(char col, char mark) {
if(empty())
return;
myfile << "X = [] \n";
myfile << "Y = [] \n";
myfile << "Z = [] \n";
myfile << "C = [] \n";
PythonAxis(0, 'X');
PythonAxis(1, 'Y');
PythonAxis(2, 'Z');
PythonAxis(0, 'X');
PythonAxis(2, 'Y');
PythonAxis(1, 'Z');
PythonAxis(1, 'X');
PythonAxis(0, 'Y');
PythonAxis(2, 'Z');
PythonAxis(1, 'X');
PythonAxis(2, 'Y');
PythonAxis(0, 'Z');
PythonAxis(2, 'X');
PythonAxis(0, 'Y');
PythonAxis(1, 'Z');
PythonAxis(2, 'X');
PythonAxis(1, 'Y');
PythonAxis(0, 'Z');
myfile << "C.extend(['" << col << "']*" << 6*size() << ") \n";
myfile << "ax.scatter(X, Y, Z, marker = '" << mark << "', c = C) \n";
}
void PythonEngine::PythonEnd() {
myfile.close();
}