時間と電圧に関するCSVファイルをグラフ化したいのですが、横軸・縦軸に軸名を表示できないです。
またグリッドの表示もうまくできないです。
グラフ描画したいデータ:
書いたプログラム:
Python
1import pandas as pd 2import matplotlib.pyplot as plt 3 4#CSVファイルをUTF-8形式で読み込む 5 6plt = pd.read_csv('000.csv',encoding = 'UTF8', index_col='time') 7plt.xlabel("time $\it{t}$ ns",fontsize=22) 8plt.ylabel("Gate-Source Voltage $\it{V_{\mathsf{GS}}}}$ V",fontsize=22) 9#dataを出力 10#plt.grid() 11plt.plot()
実行結果:
Python
1runfile('C:/Users/ISDka/.spyder-py3/testCSV.py', wdir='C:/Users/ISDka/.spyder-py3') 2Traceback (most recent call last): 3 4 File C:\anaconda\lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec 5 exec(code, globals, locals) 6 7 File c:\users\isdka\.spyder-py3\testcsv.py:7 8 plt.xlabel("Drain Voltage $\it{V_{\mathsf{DS}}}$ V",fontsize=22) 9 10 File C:\anaconda\lib\site-packages\pandas\core\generic.py:5902 in __getattr__ 11 return object.__getattribute__(self, name) 12 13AttributeError: 'DataFrame' object has no attribute 'xlabel' 14 15
修正したプログラム(今度はデータを描画できない):
Python
1import pandas as pd 2import matplotlib.pyplot as plt 3 4#CSVファイルをUTF-8形式で読み込む 5 6df = pd.read_csv('000.csv',encoding = 'UTF8', index_col='time') 7plt.xlabel("Time $\it{t}$ ns",fontsize=22) 8plt.ylabel("Gate-Source Voltage $\it{V_{\mathsf{GS}}}}$ V",fontsize=22) 9#dataを出力 10#plt.grid() 11plt.plot()
修正したプログラムの結果:
再度修正したプログラム:
Python
1import pandas as pd 2import matplotlib.pyplot as plt 3 4#CSVファイルをUTF-8形式で読み込む 5 6df = pd.read_csv('000.csv',encoding = 'UTF8', index_col='time') 7plt.xlabel("Time $\it{t}$ ns",fontsize=22) 8plt.ylabel("Gate-Source Voltage $\it{V_{\mathsf{GS}}}}$ V",fontsize=22) 9#dataを出力 10plt.grid() 11df.plot()
再度修正したプログラムの1回目の実行結果:
再度修正したプログラムの2回目の実行結果:
最終的なプログラム(回答者様のコードをCSVを取り込められるように改変):
Python
1import pandas as pd 2import matplotlib.pyplot as plt 3 4#CSVファイルをUTF-8形式で読み込む 5 6df = pd.read_csv('000.csv',encoding = 'UTF8', index_col='time') 7ax = df.plot() 8ax.set_xlabel("Time $\it{t}$ ns",fontsize=10) 9ax.set_ylabel("Gate-Source Voltage $\it{V_{\mathsf{GS}}}}$ V",fontsize=10) 10ax.grid() 11ax.plot()
実行結果(目的のグラフを描画できた):
回答1件
あなたの回答
tips
プレビュー
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2023/04/26 11:31
2023/04/26 11:52
2023/04/26 11:52
2023/04/26 12:04
2023/04/26 12:13 編集
2023/04/26 12:25 編集