- Код для воспроизведения
import matplotlib.pyplot as plt
a = [1, 2, 3]
plt.plot(a)
plt.show()
Фактический результат
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "D:\PyCharm 2019.1.2\plugins\python\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile
pydev_imports.execfile(filename, global_vars, local_vars) # execute the script
File "D:\PyCharm 2019.1.2\plugins\python\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "D:/Code/PycharmProjects/Practice01/plot03.py", line 5, in <module>
plt.show()
File "D:\Code\PycharmProjects\Practice01\venv\lib\site-packages\matplotlib\pyplot.py", line 269, in show
return _show(*args, **kw)
File "D:\PyCharm 2019.1.2\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py", line 27, in __call__
manager.show(**kwargs)
File "D:\PyCharm 2019.1.2\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py", line 99, in show
self.canvas.show()
File "D:\PyCharm 2019.1.2\plugins\python\helpers\pycharm_matplotlib_backend\backend_interagg.py", line 80, in show
display(DisplayDataObject(plot_index, width, buffer))
File "D:\PyCharm 2019.1.2\plugins\python\helpers\pycharm_display\datalore\display\display_.py", line 33, in display
_send_display_message({
File "D:\PyCharm 2019.1.2\plugins\python\helpers\pycharm_display\datalore\display\display_.py", line 48, in _send_display_message
urlopen(url, buffer)
File "C:\Python\Python38\lib\urllib\request.py", line 222, in urlopen
return opener.open(url, data, timeout)
File "C:\Python\Python38\lib\urllib\request.py", line 525, in open
response = self._open(req, data)
File "C:\Python\Python38\lib\urllib\request.py", line 542, in _open
result = self._call_chain(self.handle_open, protocol, protocol +
File "C:\Python\Python38\lib\urllib\request.py", line 502, in _call_chain
result = func(*args)
File "C:\Python\Python38\lib\urllib\request.py", line 806, in <lambda>
meth(r, proxy, type))
File "C:\Python\Python38\lib\urllib\request.py", line 814, in proxy_open
if req.host and proxy_bypass(req.host):
File "C:\Python\Python38\lib\urllib\request.py", line 2735, in proxy_bypass
return proxy_bypass_registry(host)
File "C:\Python\Python38\lib\urllib\request.py", line 2702, in proxy_bypass_registry
fqdn = socket.getfqdn(rawHost)
File "C:\Python\Python38\lib\socket.py", line 756, in getfqdn
hostname, aliases, ipaddrs = gethostbyaddr(name)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb7 in position 0: invalid start byte
Ожидаемый результат
Show line chart in SciView's plots
Среда выполнения
Operating system: Windows 10 Professional 64-bit
Matplotlib version: 3.1.3
Python version: 3.8.1
Попробуйте решить проблему самостоятельно, но не удалось
Найдена ошибка
Previously I was able to run this code in PyCharm, which can display line charts in SciView's Plots.
Soon I ran this same code again, but got the UnicodeDecodeError as above.
Устраните самостоятельно
After debugging, it was found that there was a problem with the line of plt.show ()
I run the entire code again, in Jupyter Notebook and it can run normally.
It can be seen that it is not a problem with the overall code, but may be a problem with the environment.
So I upgraded matplotlib from 3.1.2 to 3.1.3 and found that the code still does not work.
Задача поиска Google
Can't solve it independently, I had to googling for 'plt.show () occurs UnicodeDecodeError'
Временное решение
Found a solution on CSDN for UnicodeDecodeError in matplotlib in python2.7:
Create a new sitecustomize.py in the Project\venv\Lib\site-packages folder, and add the following code to the new python file:
import sys
reload (sys)
sys.setdefaultencoding ('gbk')
Временная попытка
Although my python interpreter version is 3.8.1, I still tried it in PyCharm.
It may be because this is a solution for python2.7, so I found that it can run successfully in Backend TkAgg
But cannot display the line chart in SciView Plots.
Задайте вопрос по StackOverFlow
The temporary attempt failed and no answer was found in StackOverFlow.
So I asked this question, thanks in advance to those who answered it.
Акцент на ожидаемый результат снова
Show line chart in SciView's plots
Пожалуйста, просветите меня