回答編集履歴
1
修正
test
CHANGED
@@ -41,3 +41,93 @@
|
|
41
41
|
|
42
42
|
|
43
43
|
8次の式となると以上のように長くなってしまうので、グラフ中に描画することは視認性が悪くなり、おすすめできません。
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
## 追記
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
plt.text(x, y, テキスト) で位置 (x, y) にテキストを表示できます。
|
52
|
+
|
53
|
+
位置は適宜変更してください
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
```python
|
60
|
+
|
61
|
+
import pandas as pd
|
62
|
+
|
63
|
+
import csv
|
64
|
+
|
65
|
+
import numpy as np
|
66
|
+
|
67
|
+
import matplotlib.pyplot as plt
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
x = np.linspace(0, 2, 15)
|
74
|
+
|
75
|
+
y = np.sin(x) + np.random.normal(scale=0.05, size=len(x))
|
76
|
+
|
77
|
+
|
78
|
+
|
79
|
+
plt.rcParams["ytick.direction"] = "in"
|
80
|
+
|
81
|
+
plt.rcParams["xtick.direction"] = "in"
|
82
|
+
|
83
|
+
plt.gca().yaxis.set_major_formatter(plt.FormatStrFormatter("%.1f"))
|
84
|
+
|
85
|
+
plt.gca().xaxis.set_major_formatter(plt.FormatStrFormatter("%.1f"))
|
86
|
+
|
87
|
+
plt.rcParams["font.family"] = "sans-serif"
|
88
|
+
|
89
|
+
plt.rcParams["xtick.major.width"] = 1.0
|
90
|
+
|
91
|
+
plt.rcParams["ytick.major.width"] = 1.0
|
92
|
+
|
93
|
+
plt.rcParams["font.size"] = 8
|
94
|
+
|
95
|
+
plt.rcParams["axes.linewidth"] = 1.0
|
96
|
+
|
97
|
+
plt.ylabel("V(V)")
|
98
|
+
|
99
|
+
plt.xlabel("t(s)")
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
# 近似式の係数
|
104
|
+
|
105
|
+
res1 = np.polyfit(x, y, 8)
|
106
|
+
|
107
|
+
y1 = np.poly1d(res1)(x)
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
eq = " + \n".join(f"{a:10.2e} x^{len(res1) - i}" for i, a in enumerate(res1, 1))
|
112
|
+
|
113
|
+
print(eq)
|
114
|
+
|
115
|
+
|
116
|
+
|
117
|
+
# グラフ表示
|
118
|
+
|
119
|
+
plt.text(0, 1.12, eq, fontsize=15)
|
120
|
+
|
121
|
+
plt.scatter(x, y, label="Orignal")
|
122
|
+
|
123
|
+
plt.plot(x, y1, color="red", label="1st order")
|
124
|
+
|
125
|
+
plt.legend()
|
126
|
+
|
127
|
+
plt.show()
|
128
|
+
|
129
|
+
```
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
![イメージ説明](c975944aefb1315cb1e9fdaacb156d5f.jpeg)
|