I get TypeError: can't multiply sequence by non-int of type 'numpy.float64' when trying to save a plot in Python

I get TypeError: can't multiply sequence by non-int of type 'numpy.float64' when trying to save a plot in Python

# This is my code that creates the plot
moving_avg = np.convolve(list_of_results, np.ones((100,)) / 100, mode="valid")
plt.plot([i for i in range(len(moving_avg))], moving_avg)
plt.ylabel('Remaining Pins')
plt.xlabel('Games played')
plt.grid()
plt.savefig('English_10000.pdf', dpi='300')
Traceback (most recent call last):
  File "C:/Users/lovir/Desktop/Backup/project_solitaer/display.py", line 144, in <module>
    plt.savefig('English_10000.pdf', dpi='300')
  File "C:\Users\lovir\env\lib\site-packages\matplotlib\pyplot.py", line 859, in savefig
    res = fig.savefig(*args, **kwargs)
  File "C:\Users\lovir\env\lib\site-packages\matplotlib\figure.py", line 2311, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "C:\Users\lovir\env\lib\site-packages\matplotlib\backend_bases.py", line 2162, in print_figure
    with cbook._setattr_cm(self, manager=None), \
  File "C:\Users\lovir\AppData\Local\Programs\Python\Python38\lib\contextlib.py", line 113, in __enter__
    return next(self.gen)
  File "C:\Users\lovir\env\lib\site-packages\matplotlib\cbook\__init__.py", line 2079, in _setattr_cm
    setattr(obj, attr, val)
  File "C:\Users\lovir\env\lib\site-packages\matplotlib\figure.py", line 451, in _set_dpi
    self.dpi_scale_trans.clear().scale(dpi)
  File "C:\Users\lovir\env\lib\site-packages\matplotlib\transforms.py", line 1996, in scale
    self._mtx[0, 0] *= sx
TypeError: can't multiply sequence by non-int of type 'numpy.float64'

Process finished with exit code 1

如果我使用我的 32 位版本的 python 绘图工作正常,但是当我使用 pickle 时出现内存错误,所以我切换到 64 位 python。但是现在当我尝试保存绘图时出现此错误。

阅读 savefig (https://matplotlib.org/api/_as_gen/matplotlib.pyplot.savefig.html) 的文档。

dpi 参数指定为 float,而您传递了 string.

尝试 dpi=300(不带撇号)。