実現したいこと
ここに実現したいことを箇条書きで書いてください。
オシロスコープのデータをとってくる
オシロスコープにて抽出したデータをプロットする
プロットした縦軸は電圧、横軸は時間
前提
ここに質問の内容を詳しく書いてください。
・jupyter notebook にてオシロスコープを用いて測定したい
・条件としては電圧は10数V
・周波数は13MHzから18MHzほどのものを測定したい
数十MHzということなので、横軸を1メモリ100ns等に変えようと思っていたのですが
突然x、yの変数の型が違うというエラーメッセージがでできた
発生している問題・エラーメッセージ
ValueError Traceback (most recent call last)
Cell In[11], line 69
63 plt.pause(.01)
68 if name == "main":
---> 69 main()
Cell In[11], line 45, in main()
42 ax.set_xlabel('time(μs)')
43 ax.set_ylabel('Voltage(mV)')
---> 45 lines, = ax.plot(x, y)
47 while True:
49 manager = _pylab_helpers.Gcf.get_active()
File ~\anaconda3\lib\site-packages\matplotlib\axes_axes.py:1688, in Axes.plot(self, scalex, scaley, data, *args, **kwargs)
1445 """
1446 Plot y versus x as lines and/or markers.
1447
(...)
1685 ('green'
) or hex strings ('#008000'
).
1686 """
1687 kwargs = cbook.normalize_kwargs(kwargs, mlines.Line2D)
-> 1688 lines = [*self._get_lines(*args, data=data, **kwargs)]
1689 for line in lines:
1690 self.add_line(line)
File ~\anaconda3\lib\site-packages\matplotlib\axes_base.py:311, in _process_plot_var_args.call(self, data, *args, **kwargs)
309 this += args[0],
310 args = args[1:]
--> 311 yield from self._plot_args(
312 this, kwargs, ambiguous_fmt_datakey=ambiguous_fmt_datakey)
File ~\anaconda3\lib\site-packages\matplotlib\axes_base.py:504, in _process_plot_var_args._plot_args(self, tup, kwargs, return_kwargs, ambiguous_fmt_datakey)
501 self.axes.yaxis.update_units(y)
503 if x.shape[0] != y.shape[0]:
--> 504 raise ValueError(f"x and y must have same first dimension, but "
505 f"have shapes {x.shape} and {y.shape}")
506 if x.ndim > 2 or y.ndim > 2:
507 raise ValueError(f"x and y can be no greater than 2D, but have "
508 f"shapes {x.shape} and {y.shape}")
ValueError: x and y must have same first dimension, but have shapes (101,) and (100,)
該当のソースコード
python
def get_data_from_inst(rm , osc): osc.timeout = 30000 # Setting source as Channel 1 osc.write('DATA:SOU CH1') osc.write('DATA:WIDTH 1') osc.write('DATA:ENC ASCI') osc.write('DATA:RESOLUTION FULL') # Getting axis info ymult = float(osc.query('WFMPRE:YMULT?')) # y-axis least count yzero = float(osc.query('WFMPRE:YZERO?')) # y-axis zero error yoff = float(osc.query('WFMPRE:YOFF?')) # y-axis offset xincr = float(osc.query('WFMPRE:XINCR?')) # x-axis least count xoff = float(osc.query('WFMP:PT_OFF?')) # x-axis offset xzero = float(osc.query('WFMPRE:XZERO?')) # x-axis least count ADC_wave = osc.query_ascii_values('CURV?', container=np.array) Volts = (ADC_wave- yoff) * ymult + yzero Time = np.arange(xzero,len(Volts)*xincr + xzero, xincr) return (Time, Volts) def main(): rm = pyvisa.ResourceManager() osc = rm.open_resource(rm.list_resources()[0]) data = get_data_from_inst(rm, osc) x, y = data x = x * 1e6 # sec to micro sec y = y * 1e3 # V to mV fig, ax = plt.subplots(1, 1) ax.set_xlabel('time(μs)') ax.set_ylabel('Voltage(mV)') lines, = ax.plot(x, y) while True: manager = _pylab_helpers.Gcf.get_active() if manager is None: break # plot データの更新 data = get_data_from_inst(rm, osc) x, y = data x = x * 1e6 # sec to micro sec y = y * 1e3 # V to mV # data update lines.set_data(x, y) plt.pause(.01) if __name__ == "__main__": main()
試したこと
Time = np.arange(xzero, xincr * (len(Volts) - xoff) + xzero, xincr)から
Time = np.arange(xzero,len(Volts)*xincr + xzero, xincr)に変更しました
補足情報(FW/ツールのバージョン
オシロスコープにはTEKTRONIX,DPO3014,C021244,CF:91.1CT FV:v2.38
これを用いています
