Matplotlib绘图时绘图

请参阅matplotlib绘图代码,但有时我遇到以下错误。

  if np.any(harmonics == 1) or np.any(harmonics == -1):
        for j in range (0,len(harmonics)):
            if harmonics[j] == 1 or harmonics[j]==-1:
                pats+=1
                sense = 'Bearish ' if harmonics[j]==-1 else 'Bullish '
                label = sense + labels[j] + ' found' 
                print(label)
                plt.title(label)
                plt.plot(np.arange(start,i+15),price.values[start:i+15])
                plt.scatter(current_idx,current_pat,c='r')
                filename = str(uuid.uuid1())[:8]
                print(filename)
                plt.savefig(filename)
                plt.close(filename)
                plt.show()

关于错误的跟踪,当我使用相同的代码巨大的数据输入时,它正在工作,但是如果我使用较少的数据,同样会失败

Traceback (most recent call last):
  File "peaks_vis-san.py", line 99, in <module>
    plt.plot(np.arange(start,i+15),price.values[start:i+15])
  File "/usr/local/lib64/python3.6/site-packages/matplotlib/pyplot.py", line 2763, in plot
    is not None else {}), **kwargs)
  File "/usr/local/lib64/python3.6/site-packages/matplotlib/axes/_axes.py", line 1646, in plot
    lines = [*self._get_lines(*args, data=data, **kwargs)]
  File "/usr/local/lib64/python3.6/site-packages/matplotlib/axes/_base.py", line 216, in __call__
    yield from self._plot_args(this, kwargs)
  File "/usr/local/lib64/python3.6/site-packages/matplotlib/axes/_base.py", line 342, in _plot_args
    raise ValueError(f"x and y must have same first dimension, but "
ValueError: x and y must have same first dimension, but have shapes (41,) and (34,)
评论