これは、matplotlib で pyplot を使用して収集したデータをプロットしようとするとエラーが発生する、キューを介したデータ転送を伴うマルチスレッド Python スクリプト (threading.thread) の一部です。
このスクリプト全体は、以前のバージョンでは機能していました。唯一の変更点は、それぞれ pickle.dump と pickle.load を使用してデータ配列を保存およびロードすることです。このデバッグ バージョンでは、ロードが有効になっていません。
含まれているスレッドによって分割された、失敗した関連コードを次に示します。
メインループ (スレッド):
elif kbcheck == 'p':
print "I KNOW YOU TYPED P" # Debug to see if plotting is triggered.
PLOTFLAGQ.put(1)
データ処理スレッド:
self.PLOTQL = [self.RAL, self.THD_avgL, self.VacL,
self.IacL, self.PacL, self.VdcL,
self.IdcL, self.PdcL, self.tempL]
if not self.PLOTFLAGQ.empty():
self.plotflag = self.PLOTFLAGQ.get()
self.PLOTQ.put(self.PLOTQL)
プロットスレッドで:
if not self.PLOTQ.empty():
(self.RAL, self.THD_avgL, self.VacL, self.IacL,
self.PacL, self.VdcL, self.IdcL, self.PdcL,
self.TempL) = self.PLOTQ.get()
self.XaxisL = []
for i in range(len(self.VacL)):
self.XaxisL.append(i+1)
self.fig = pyplot.figure()
self.gs = gridspec.GridSpec(6,1, height_ratios = [1,2,2,2,2,2])
self.sT = pyplot.subplot(self.gs[0])
self.sT.yaxis.set_major_locator(pyplot.MaxNLocator(5))
self.sV = pyplot.subplot(self.gs[1])
self.sV.yaxis.set_major_locator(pyplot.MaxNLocator(10))
self.Va = self.sV.plot(self.XaxisL,self.VacL,
'-b',label = 'Voltage (AC)')
デバッグ情報は次のとおりです。
17
Here is the info in the Plot Thread
the length of VacL is: 17
[250.119, 250.156, 250.19, 250.193, 250.206, 250.158, 250.107, 250.103, 250.159, 250.156, 250.146, 250.093, 250.084, 250.095, 250.134, 250.0
35, 249.994]
the length of the x axis is: 17
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]
出力の上には、サンプリングのカウント (17)、次に Vac リスト配列とその長さが表示され、その後に x 軸配列 (他の値の長さから派生) が続きます。
エラーは次のとおりです。
Exception in thread Thread-5:
Traceback (most recent call last):
File "C:\Python27\lib\threading.py", line 552, in __bootstrap_inner
self.run()
File "C:\Projects\PythonScripts\Matthew_Threading_2_v0.3.3db.py", line 273, in run
self.Va = self.sV.plot(self.XaxisL,self.VacL,"-b",label = "Voltage AC")
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 3848, in plot
for line in self._get_lines(*args, **kwargs):
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 323, in _grab_next_args
for seg in self._plot_args(remaining, kwargs):
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 300, in _plot_args
x, y = self._xy_from_xy(x, y)
File "C:\Python27\lib\site-packages\matplotlib\axes.py", line 240, in _xy_from_xy
raise ValueError("x and y must have same first dimension")
ValueError: x and y must have same first dimension
プログラム全体を 2 回書き直し、保存スレッド (プロットを壊しているように見える部分) だけをさらに 2 回書き直しましたが、このエラーの原因がわかりません。
誰かが私を助けることができれば、それは大歓迎です。ありがとうございました!