Traceback (most recent call last): File "D:\pythonProject5\main.py", line 209, in <module> main() File "D:\pythonProject5\main.py", line 202, in main plt.subplot(-1, 4, i+1) File "D:\Users\lenovo\anaconda3\lib\site-packages\matplotlib\pyplot.py", line 1323, in subplot key = SubplotSpec._from_subplot_args(fig, args) File "D:\Users\lenovo\anaconda3\lib\site-packages\matplotlib\gridspec.py", line 587, in _from_subplot_args gs = GridSpec._check_gridspec_exists(figure, rows, cols) File "D:\Users\lenovo\anaconda3\lib\site-packages\matplotlib\gridspec.py", line 226, in _check_gridspec_exists return GridSpec(nrows, ncols, figure=figure) File "D:\Users\lenovo\anaconda3\lib\site-packages\matplotlib\gridspec.py", line 379, in __init__ super().__init__(nrows, ncols, File "D:\Users\lenovo\anaconda3\lib\site-packages\matplotlib\gridspec.py", line 49, in __init__ raise ValueError( ValueError: Number of rows must be a positive integer, not -1 进程已结束,退出代码1
时间: 2023-07-21 16:26:44 浏览: 150
浅谈Python traceback的优雅处理
这段代码中的报错信息显示,`plt.subplot` 函数的第一个参数传递了 `-1`,而实际上行数必须是正整数。因此,需要检查该函数调用的参数是否正确。建议将 `plt.subplot(-1, 4, i+1)` 改为 `plt.subplot(2, 2, i+1)`,表示将图形分成 2 行 2 列,总共 4 个子图,第 `i+1` 个子图。这样就能避免该报错。
阅读全文