Cell In[14], line 5 3 plt.figure(figsize=(12, 5)) 4 plt.plot(np.arange(len(y_test)), y_test[index], "r", label="Original Y") ----> 5 plt.scatter(np.arange(len(pre_y[index])), s=3, c="b", label="Prediction") 6 plt.legend(loc="upper left") 7 plt.grid() TypeError: scatter() missing 1 required positional argument: 'y'
时间: 2023-06-25 15:02:28 浏览: 189
这个错误是因为 `scatter()` 函数需要两个参数 `x` 和 `y`,但是你只提供了一个参数 `x`,所以出现了缺少一个位置参数的错误。你需要在 `scatter()` 函数中提供 `y` 参数。
你可以将 `pre_y[index]` 作为 `y` 参数传递给 `scatter()` 函数,例如:
```python
plt.scatter(np.arange(len(pre_y[index])), pre_y[index], s=3, c="b", label="Prediction")
```
这样就可以解决这个错误了。
相关问题
plt.figure(figsize=(10,8)) plt.plot(list(np.arange(0,len(data1_0))),data1_0,label='原序列') plt.plot(list(np.arange(0,len(data1_0))),data1_1_3,label='平滑后的序列') plt.title('移动平均法(窗口大小为3个)数据平滑对比图') plt.xlabel('时间序列') plt.ylabel('速度(km/h)') plt.xticks(range(0,110,10)) plt.legend() plt.show() plt.figure(figsize=(10,8)) plt.plot(list(np.arange(0,len(data1_0))),data1_0,label='原序列') plt.plot(list(np.arange(0,len(data1_0))),data1_1_5,label='平滑后的序列') plt.title('移动平均法(窗口大小为5个)数据平滑图') plt.xlabel('时间序列') plt.ylabel('速度(km/h)') plt.xticks(range(0,110,10)) plt.legend() plt.show()如何将两幅图合并
可以使用subplot函数将两幅图合并:
plt.figure(figsize=(10,8))
plt.subplot(2,1,1)
plt.plot(list(np.arange(0,len(data1_0))),data1_0,label='原序列')
plt.plot(list(np.arange(0,len(data1_0))),data1_1_3,label='平滑后的序列')
plt.title('移动平均法(窗口大小为3个)数据平滑对比图')
plt.xlabel('时间序列')
plt.ylabel('速度(km/h)')
plt.xticks(range(0,110,10))
plt.legend()
plt.subplot(2,1,2)
plt.plot(list(np.arange(0,len(data1_0))),data1_0,label='原序列')
plt.plot(list(np.arange(0,len(data1_0))),data1_1_5,label='平滑后的序列')
plt.title('移动平均法(窗口大小为5个)数据平滑图')
plt.xlabel('时间序列')
plt.ylabel('速度(km/h)')
plt.xticks(range(0,110,10))
plt.legend()
plt.show()
解释这段代码def plot_confusion_matrix(cm, title='混淆矩阵', cmap=plt.cm.Blues, labels=[]): plt.figure(figsize=(8,8),dpi=600) plt.imshow(cm, interpolation='nearest', cmap=cmap) plt.title(title,fontsize=15) plt.colorbar(fraction=0.045,pad=0.05) tick_marks = np.arange(len(labels)) ind_array = np.arange(len(classes)) x, y = np.meshgrid(ind_array, ind_array)
这段代码是用于绘制混淆矩阵的,用于评估分类模型的性能表现。其中,输入参数cm表示混淆矩阵,title表示图表标题,cmap表示颜色映射,labels表示类别标签。这段代码使用了matplotlib库和numpy库来完成图表绘制和数据处理。
阅读全文
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)