出错的程序源代码:
看到这个源代码,大家应该疑惑了吧,这是对的啊!!!!
但是报错了:D:\PycharmProjects\python_project\venv\Scripts\python.exe D:/PycharmProjects/python_project/matplotlib/04绘制一元二次方程曲线.py
Traceback (most recent call last):
File "D:/PycharmProjects/python_project/matplotlib/04绘制一元二次方程曲线.py", line 11, in
plt.savefig('result.jpg')
File "D:\PycharmProjects\python_project\venv\lib\site-packages\matplotlib\pyplot.py", line 729, in savefig
res = fig.savefig(*args, **kwargs)
File "D:\PycharmProjects\python_project\venv\lib\site-packages\matplotlib\figure.py", line 2180, in savefig
self.canvas.print_figure(fname, **kwargs)
File "D:\PycharmProjects\python_project\venv\lib\site-packages\matplotlib\backend_bases.py", line 2023, in print_figure
canvas = self._get_output_canvas(format)
File "D:\PycharmProjects\python_project\venv\lib\site-packages\matplotlib\backend_bases.py", line 1965, in _get_output_canvas
.format(fmt, ", ".join(sorted(self.get_supported_filetypes()))))
ValueError: Format 'jpg' is not supported (supported formats: eps, pdf, pgf, png, ps, raw, rgba, svg, svgz)
Process finished with exit code 1
这是什么原因呢?原来啊,是我们少安装了一个pillow模块!!!!!!!解决方案是:安装这个模块,再执行即可。
执行的安装模块指令:pip install pillow -i https://pypi.tuna.tsinghua.edu.cn/simple
如此便可以成功了!!!如图为安装指令执行成功:
最后程序执行成功!!