pyplot savefig вызывает OSError: [Errno 9] Неверный дескриптор файла - PullRequest
0 голосов
/ 02 ноября 2018

Когда я пытался сохранить фигуру matplotlib в файл, я получал ошибку описания плохого файла. Мой код выглядит следующим образом:

import os
os.chdir('C:\\users\\mutas\\documents\\')

import matplotlib.pyplot as plt
plt.text(0.5,0.5, 'some text')

if os.path.isfile('c.png'):
    plt.savefig('c.png')

При запуске возникает следующая ошибка:

OSError: [Errno 9] Bad file descriptor

The above exception was the direct cause of the following exception:

SystemError: <built-in method write of _io.BufferedWriter object at 
0x0C7E0360> returned a result with an error set

The above exception was the direct cause of the following exception:

SystemError: <built-in method write of _io.BufferedWriter object at 
0x0C7E0360> returned a result with an error set

The above exception was the direct cause of the following exception:

SystemError: <built-in method write of _io.BufferedWriter object at 
0x0C7E0360> returned a result with an error set

The above exception was the direct cause of the following exception:

SystemError: <built-in method write of _io.BufferedWriter object at 
0x0C7E0360> returned a result with an error set

The above exception was the direct cause of the following exception:

SystemError: <built-in method write of _io.BufferedWriter object at 
0x0C7E0360> returned a result with an error set

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "C:\Program Files (x86)\Python37-32\lib\site- 
packages\matplotlib\cbook\__init__.py", line 410, in open_file_cm
yield fh
File "C:\Program Files (x86)\Python37-32\lib\site- 
packages\matplotlib\backends\backend_agg.py", line 523, in print_png
self.figure.dpi, metadata=metadata)
SystemError: <built-in method write of _io.BufferedWriter object at 
0x0C7E0360> returned a result with an error set

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\mutas\Documents\tpf01.py", line 8, in <module>
plt.savefig('c.png')
File "C:\Program Files (x86)\Python37-32\lib\site- 
packages\matplotlib\pyplot.py", line 688, in savefig
res = fig.savefig(*args, **kwargs)
File "C:\Program Files (x86)\Python37-32\lib\site- 
packages\matplotlib\figure.py", line 2097, in savefig
self.canvas.print_figure(fname, **kwargs)
File "C:\Program Files (x86)\Python37-32\lib\site-packages\matplotlib\backend_bases.py", line 2075, in print_figure
**kwargs)
File "C:\Program Files (x86)\Python37-32\lib\site- 
packages\matplotlib\backends\backend_agg.py", line 523, in print_png
self.figure.dpi, metadata=metadata)
File "C:\Program Files (x86)\Python37-32\lib\contextlib.py", line 130, in 
__exit__
self.gen.throw(type, value, traceback)
File "C:\Program Files (x86)\Python37-32\lib\site- 
packages\matplotlib\cbook\__init__.py", line 410, in open_file_cm
yield fh
OSError: [Errno 9] Bad file descriptor

Что здесь происходит? Обратите внимание, что это не новая установка matplotlib в системе. Я уже некоторое время использую это, и эта проблема внезапно начала возникать.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...