Skip to content

Commit cf45af9

Browse files
committed
Добавлены настройки
1 parent 4b18c67 commit cf45af9

File tree

10 files changed

+226
-144
lines changed

10 files changed

+226
-144
lines changed

graph/contour_graph.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,19 @@
44

55
from graph.mpl_canvas import MlpCanvas
66

7+
from settings import Settings
8+
79

810
class CanvasContourGraph(MlpCanvas):
9-
def create_graph(self, constraints_high, constraints_down, func, h=0.1, delta=0.2, amp_noise=0, l=2):
10-
x, y, z, levels = self.make_data(constraints_high, constraints_down, func, h=h, delta=delta, amp_noise=amp_noise, l=l)
11-
# TODO: добавить подпись для легенды
11+
def create_graph(self, constraints_high, constraints_down, func, h=0.1, delta=1, amp_noise=0):
12+
x, y, z, levels = self.make_data(constraints_high, constraints_down, func,
13+
h=h, delta=delta, amp_noise=amp_noise)
1214
plt.contour(x, y, z, levels=levels)
1315
self.axes.grid()
1416

15-
def make_data(self, constraints_high, constraints_down, func, h=0.2, delta=0.3, amp_noise=0, l=2):
16-
x = np.arange(constraints_down[0], constraints_high[0], h)
17-
y = np.arange(constraints_down[1], constraints_high[1], h)
17+
def make_data(self, constraints_high, constraints_down, func, h=0.2, delta=1, amp_noise=0):
18+
x = np.arange(constraints_down[0], constraints_high[0], Settings.settings['grid_spacing'].value)
19+
y = np.arange(constraints_down[1], constraints_high[1], Settings.settings['grid_spacing'].value)
1820
xgrid, ygrid = np.meshgrid(x, y)
1921

2022
zgrid = np.zeros(xgrid.shape)
@@ -26,13 +28,14 @@ def make_data(self, constraints_high, constraints_down, func, h=0.2, delta=0.3,
2628
zgrid[i][j] = zgrid[i][j] + np.random.uniform(-amp_noise, amp_noise)
2729

2830
levels = []
29-
for i in self.get_delta(np.min(zgrid), np.max(zgrid), delta=delta, l=l):
31+
for i in self.get_delta(np.min(zgrid), np.max(zgrid),
32+
delta=delta, l=Settings.settings['contour_level_step'].value):
3033
levels.append(i)
3134

3235
return xgrid, ygrid, zgrid, levels
3336

34-
def get_delta(self, min_z, max_z, delta=0.5, l=0.5):
35-
j = 1
37+
def get_delta(self, min_z, max_z, delta=1., l=0.5):
38+
j = 0 # 1
3639
while min_z < max_z:
3740
min_z = min_z + (delta * j)
3841
yield min_z

graph/graph_3d.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,26 @@
44

55
from graph.mpl_canvas import MlpCanvas
66

7+
from settings import Settings
8+
79

810
class Canvas3dGraph(MlpCanvas):
911
def create_graph(self, constraints_high, constraints_down, func, h=0.2, subplot_n=2, subplot_m=2):
10-
x, y, z = self.make_data(constraints_high, constraints_down, func, h=0.2)
12+
x, y, z = self.make_data(constraints_high, constraints_down, func, h=h)
1113
# TODO: добавить подпись для легенды
1214
self.axes = Axes3D(self.fig)
13-
# ax = fig.add_subplot(111, projection='3d')
1415
self.axes.plot_surface(x, y, z,
15-
rstride=4,
16-
cstride=4,
16+
rstride=Settings.settings['rstride'].value,
17+
cstride=Settings.settings['cstride'].value,
1718
cmap=plt.get_cmap('Spectral'))
1819
self.axes.grid()
1920

2021
def make_data(self, constraints_high, constraints_down, func, h=0.2):
21-
x = np.arange(constraints_down[0], constraints_high[0], h)
22-
y = np.arange(constraints_down[1], constraints_high[1], h)
22+
x = np.arange(constraints_down[0], constraints_high[0], Settings.settings['grid_spacing'].value)
23+
y = np.arange(constraints_down[1], constraints_high[1], Settings.settings['grid_spacing'].value)
2324
xgrid, ygrid = np.meshgrid(x, y)
2425

2526
zgrid = np.zeros(xgrid.shape)
26-
# zgrid = np.zeros(xgrid.shape)
27-
28-
# for i in range(xgrid.shape[0]):
29-
# for j in range(xgrid.shape[1]):
30-
# zgrid[i][j] = func([xgrid[i], ygrid[j]])
3127

3228
for i in range(xgrid.shape[0]):
3329
for j in range(xgrid.shape[1]):

graph/slice_graph.py

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import numpy as np
22
import sympy
3-
# import matplotlib.pyplot as plt
43

54
from graph.mpl_canvas import MlpCanvas
65
from service import only_one_true
6+
from settings import Settings
77

88

99
class CanvasSliceGraph(MlpCanvas):
1010
"""Класс для построения графиков срезов функции"""
11-
def create_graph(self, constraints_high, constraints_down, func, expression="", axes=0, h=0.2, amp_noise=0): # self, constraints_x, constraints_y, func, expr_x="", expr_y="", expression="", axes=0, h=0.2, amp_noise=0
11+
def create_graph(self, constraints_high, constraints_down, func, expression="", axes=0, h=0.2, amp_noise=0):
1212
# TODO: добавить подпись для легенды
1313
np.random.seed()
1414

@@ -20,11 +20,10 @@ def create_graph(self, constraints_high, constraints_down, func, expression="",
2020
axes=axes,
2121
h=h,
2222
amp_noise=amp_noise)
23-
self.axes.plot(x, y, lw=1, label='F')
24-
# plt.legend(loc='center left', title=legend_title, bbox_to_anchor=(1, 0.5))
23+
self.axes.plot(x, y, lw=Settings.settings['line_thickness'].value, label='F')
2524
self.axes.grid()
2625

27-
def make_data(self, constraints_high, constraints_down, func, expression="", axes=0, h=0.2, amp_noise=0): # expression_x="", expression_y="",
26+
def make_data(self, constraints_high, constraints_down, func, expression="", axes=0, h=0.2, amp_noise=0):
2827
# TODO: сделать в параметрах одно выражение expression и номер оси для среза
2928
"""
3029
Метод генерации данных для построения графика
@@ -44,44 +43,6 @@ def make_data(self, constraints_high, constraints_down, func, expression="", axe
4443
:return: возвращает массив координат x(x1) или y(x2) и координаты функции z, одномерные массивы
4544
"""
4645
# TODO: параметрические уравнения?
47-
# if expression_x != "":
48-
# # x1
49-
# y = np.arange(constraints_y[0], constraints_y[1], h)
50-
# z = np.zeros(len(y))
51-
# if expression_x.find('y') != -1:
52-
# var_y = sympy.Symbol('y')
53-
# expr = sympy.S(expression_x)
54-
# f = sympy.lambdify(var_y, expr, "numpy")
55-
# x = f(y)
56-
# # for i in range(len(y)):
57-
# # z[i] = func([x[i], y[i]])
58-
# else:
59-
# x = float(expression_x)
60-
# for i in range(len(y)):
61-
# z[i] = func([x, y[i]])
62-
# if amp_noise > 0:
63-
# z[i] = z[i] + np.random.uniform(-amp_noise, amp_noise)
64-
# return y, z
65-
#
66-
# if expression_y != "":
67-
# # x2
68-
# x = np.arange(constraints_x[0], constraints_x[1], h)
69-
# z = np.zeros(len(x))
70-
# if expression_y.find('x') != -1:
71-
# var_x = sympy.Symbol('x')
72-
# expr = sympy.S(expression_y)
73-
# f = sympy.lambdify(var_x, expr, "numpy")
74-
# y = f(x)
75-
# # for i in range(len(x)):
76-
# # z[i] = func([x[i], y[i]])
77-
# else:
78-
# y = float(expression_y)
79-
# for i in range(len(x)):
80-
# z[i] = func([x[i], y])
81-
# if amp_noise > 0:
82-
# z[i] = z[i] + np.random.uniform(-amp_noise, amp_noise)
83-
#
84-
# return x, z
8546

8647
symbol = ["x2", "x1"]
8748
if (expression != "") and (0 <= axes < 2):

0 commit comments

Comments
 (0)