要在使用 python
命令运行含有 plt.show()
的代码时弹出图表窗口,可以在脚本中添加 plt.show(block=True)
函数来强制阻塞脚本,直到用户手动关闭图表窗口为止。例如:
import matplotlib.pyplot as plt
# 绘制图表
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
plt.title('My Plot')
plt.xlabel('X Label')
plt.ylabel('Y Label')
# 显示图表并阻塞脚本
plt.show(block=True)