forked from Gjjj74833/RTG-REU-UA-Summer-2023
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect_Kd.py
65 lines (51 loc) · 1.97 KB
/
select_Kd.py
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
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 18 20:59:58 2023
@author: ghhh7
"""
import numpy as np
import matplotlib.pyplot as plt
k_d = np.linspace(0.02, 1, 200)
data = np.load('kd_stat.npy')
std = data[:,2]
print(min(std))
plt.figure()
plt.plot(k_d, std)
plt.xlabel("Derivative gain kd")
plt.ylabel("Standard Deviation of Roter Speed")
plt.title("Standard Deviation of Controlled Rotor Speed Respect to Derivative Gain")
plt.xlim(0.02, 1)
plt.grid(True)
plt.tight_layout()
plt.show()
plt.savefig('std_kd.png', dpi=300)
plt.close()
plt.figure()
plt.plot(k_d, std)
# Find the minimum value and its corresponding k_d
min_std = np.min(std)
min_kd_idx = np.argmin(std)
min_kd = k_d[min_kd_idx]
# Adding a vertical line at the minimum point
plt.axvline(x=min_kd, color='r', linestyle='--')
# Adding a horizontal line at the minimum point
plt.axhline(y=min_std, color='r', linestyle='--')
# Label the minimum value - this will put text on the plot at the specified position
plt.text(min_kd, min_std, f'Minimum\nkd={min_kd:.2f}, std={min_std:.2f}', color='black',
ha='right', # horizontal alignment can be 'center', 'right'
va='bottom', # vertical alignment can be 'center', 'top'
bbox=dict(facecolor='white', alpha=0.8)) # this puts a white background around the text for readability
# Possibly add an arrow to the text
# plt.annotate(f'Minimum\nkd={min_kd:.2f}, std={min_std:.2f}', xy=(min_kd, min_std),
# xytext=(min_kd, min_std + some_value), # some_value depends on your data range
# arrowprops=dict(facecolor='black', shrink=0.05))
plt.xlabel("Derivative gain kd")
plt.ylabel("Standard Deviation of Rotor Speed")
plt.title("Standard Deviation of Controlled Rotor Speed Respect to Derivative Gain")
plt.xlim(0.02, 1)
plt.grid(True)
plt.tight_layout()
plt.show()
# Save the figure. This should come right after `show()` before closing, as some backends will close the figure automatically after show().
plt.savefig('std_kd.png', dpi=300)
plt.close()