Engee documentation
Notebook

How to use Python in Engee

In this example, we will look at the principles of interacting with Python from within the Engee environment, using the .ipynb file format, and do some exercises with graphs.

Getting started

Import the compute (NumPy) and graphics (matplotlib) libraries:

In [ ]:
import matplotlib.pyplot as plt # Пакет построения графиков
import numpy as np # Фундаментальный пакет для научных вычислений

Graphing

Plotting graphs by points:

In [ ]:
plt.plot([1, 2], [3, 4]) # Отрисовка возрастающего графика
plt.show() # Отображение всех ранее описанных графиков
plt.plot([1, 2], [4, 3]) # Отрисовка убывающего графика
plt.show()
No description has been provided for this image
No description has been provided for this image

image.png

image_2.png

Plotting multiple graphs

Declaring a function to draw graphs.

In [ ]:
def f(t):
    return np.exp(-t) * np.cos(2*np.pi*t) # Математическая формула

Declaring arrays.

In [ ]:
t1 = np.arange(0.0, 5.0, 0.1)
t2 = np.arange(0.0, 5.0, 0.02)

Building graphs.

In [ ]:
plt.figure() # Объявление фигуры (Пространства для отрисовки графика)
plt.subplot(211) # Объявление первого из двух окон графика
plt.plot(t1, f(t1), 'bo', t2, f(t2), 'k') 
plt.subplot(212) 
plt.plot(t2, np.cos(2*np.pi*t2), 'r--') 
plt.show() 
No description has been provided for this image

image.png

Building graphs with keywords

Declaring a list of vocabularies.

In [ ]:
data = {'a': np.arange(50), # Возвращает равномерно распределенные значения в пределах заданного интервала.
        'c': np.random.randint(0, 50, 50), # Возвращает случайное целое в заданных пределах.
        'd': np.random.randn(50)} # Возврат выборки (или выборок) из «стандартного нормального» распределения.
data['b'] = data['a'] + 10 * np.random.randn(50) # Расчёт b
data['d'] = np.abs(data['d']) * 100 # d взятый по модулю и умноженный на 100

Point drawing of the graph and axes signature.

In [ ]:
plt.scatter('a', 'b', c='c', s='d', data=data) # Точечная диаграмма зависимости y от x с разным размером маркера и/или цветом.
plt.xlabel('entry a') # Подписать ось X
plt.ylabel('entry b') # Подписать ось Y
plt.show()
No description has been provided for this image

image.png

Plotting graphs for category data

Declaring data arrays and an array of category names.

In [ ]:
names = ['group_a', 'group_b', 'group_c'] # Массив строк
values = [1, 10, 100] # Массив чисел
In [ ]:
plt.figure(figsize=(9, 3))
plt.subplot(131)
plt.bar(names, values) 
plt.subplot(132)
plt.scatter(names, values)
plt.subplot(133)
plt.plot(names, values) 
plt.suptitle('Categorical Plotting')  # Объявления заголовка графика
plt.show()
No description has been provided for this image

image.png

Conclusion

In this example we have demonstrated the capabilities of Engee in writing and implementing algorithms in Python, in today's world this capability is relevant due to the amount of functionality implemented in Python and due to its popularity.