回答編集履歴
1
正解となったプログラムの修正
test
CHANGED
@@ -1,20 +1,34 @@
|
|
1
1
|
ChatGPTに聞いて、回答を微修正したら描画できました。
|
2
2
|
```Python
|
3
|
+
|
3
4
|
import pandas as pd
|
4
5
|
import matplotlib.pyplot as plt
|
5
6
|
|
6
|
-
#CSVファイルをUTF-8形式で読み込む
|
7
|
+
# CSVファイルをUTF-8形式で読み込む
|
7
|
-
|
8
|
-
df = pd.read_csv('VL-IL.csv',encoding
|
8
|
+
df = pd.read_csv('VL-IL.csv', encoding='UTF8', index_col=0)
|
9
|
+
|
10
|
+
# Figureオブジェクトと2つのAxesオブジェクトを作成
|
9
|
-
ax =
|
11
|
+
fig, ax1 = plt.subplots()
|
10
|
-
ax2 = ax.twinx()
|
12
|
+
ax2 = ax1.twinx()
|
13
|
+
|
11
|
-
|
14
|
+
# それぞれの軸に対応するデータをプロット
|
15
|
+
ax1.plot(df.index, df['$\it{V_{\mathsf{L}}}}$ V'], color='blue')
|
16
|
+
ax2.plot(df.index, df['$\it{I_{\mathsf{L}}}}$ A'], color='red')
|
17
|
+
|
18
|
+
# x軸、y軸ラベルを設定
|
12
|
-
ax.set_xlabel("Time $\it{t}$ \u03bcs",fontsize=15)
|
19
|
+
ax1.set_xlabel("Time $\it{t}$ \u03bcs", fontsize=15)
|
13
|
-
ax.set_ylabel("Load Voltage $\it{V_{\mathsf{L}}}}$ V",fontsize=15)
|
20
|
+
ax1.set_ylabel("Load Voltage $\it{V_{\mathsf{L}}}}$ V", fontsize=15, color='blue')
|
14
|
-
ax2.set_ylabel("Load Current $\it{I_{\mathsf{L}}}}$ A",fontsize=15)
|
21
|
+
ax2.set_ylabel("Load Current $\it{I_{\mathsf{L}}}}$ A", fontsize=15, color='red')
|
22
|
+
|
23
|
+
# y軸の目盛を設定
|
24
|
+
ax1.set_xlim([0, 100.2])
|
25
|
+
ax1.set_ylim([-300, 300])
|
26
|
+
ax2.set_ylim([-1.5, 1.5])
|
27
|
+
|
28
|
+
# グリッドを表示
|
15
|
-
ax.grid()
|
29
|
+
ax1.grid()
|
30
|
+
|
16
|
-
|
31
|
+
# プロットしたグラフを保存
|
17
|
-
plt.savefig("VL-IL.pdf",bbox_inches='tight')
|
32
|
+
plt.savefig("VL-IL.pdf", bbox_inches='tight')
|
18
|
-
ax.plot()
|
19
33
|
```
|
20
34
|

|