Files
pypet_project/Visualization/main.py
T
2024-03-17 20:20:13 +03:00

52 lines
2.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import numpy as np
import matplotlib.pyplot as plt
# Заданные точки x и y для функций интерполяции
x1 = np.array([0.981, 0.949, 0.905, 0.847, 0.78, 0.703, 0.621, 0.535,\
0.448, 0.362, 0.281, 0.206, 0.14, 0.085, 0.043, 0.015, 0.001, 0.003, 0.019])
y1 = np.array([0.942, 0.913, 0.899, 0.804, 0.804, 0.732, 0.645, 0.572,\
0.486, 0.384, 0.297, 0.225, 0.152, 0.101, 0.058, 0.022, 0.007, 0, 0])
error1_x = np.array([0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001,\
0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001]) # Погрешности по оси x для функции 1
error1_y = np.array([0.03, 0.026, 0.03, 0.026, 0.03, 0.019, 0.022,\
0.012, 0.018, 0.011 ,0.008, 0.011, 0.004, 0.004, 0.004, 0, 0, 0, 0]) # Погрешности по оси y для функции 1
x2 = np.array([0.98, 0.997, 0.999, 0.985, 0.957, 0.915, 0.86, 0.794,\
0.719, 0.638, 0.552, 0.465, 0.379, 0.297, 0.22, 0.153, 0.095, 0.051, 0.019])
y2 = np.array([0.906, 0.949, 0.949, 0.928, 0.877, 0.833, 0.732,\
0.688, 0.623, 0.543, 0.457, 0.377, 0.297, 0.217, 0.152, 0.101, 0.051, 0.022, 0])
error2_x = np.array([0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001,\
0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001, 0.001]) # Погрешности по оси x для функции 2
error2_y = np.array([0.044, 0.048, 0.048, 0.048, 0.04, 0.026, 0.026, 0.029,\
0.015, 0.026, 0.008, 0.008, 0.008, 0.007, 0.011, 0.007, 0, 0, 0]) # Погрешности по оси y для функции 2
# Аппроксимация данных и построение кривых линий
poly1 = np.polyfit(x1, y1, 1)
poly2 = np.polyfit(x2, y2, 1)
x_smooth = np.linspace(x1.min(), x1.max(), 300)
y_smooth1 = np.polyval(poly1, x_smooth)
y_smooth2 = np.polyval(poly2, x_smooth)
# Построение графика с кривыми линиями и точками с ошибками по обеим осям
plt.errorbar(x1, y1, xerr=error1_x, yerr=error1_y, fmt='o')
plt.errorbar(x2, y2, xerr=error2_x, yerr=error2_y, fmt='s')
plt.plot(x_smooth, y_smooth1, label='Значения для α > 90°')
plt.plot(x_smooth, y_smooth2, label='Значения для α < 90°')
# Добавление заголовка
plt.title('Рис.1 "График зависимости отношения интенсивности для определенного угла\n\
поворота пластины и максимальной интенсивности света от угла поворота пластины"')
plt.xlabel('cos$^{2}$(φ)', loc='center')
plt.ylabel('(<I> - I$_{0}$)\n-------------\n(I$_{max}$ - I$_{0}$)', loc='center')
# Добавление миллиметровой сетки
plt.grid(True, which='both', linestyle='--')
# Добавление легенды
plt.legend()
# Отображение графика
plt.show()