小编Nat*_*han的帖子

有什么方法可以在Python中将字节图像添加到pdf中吗?

我在 pandas 中生成了一些图并将其保存在 BytesIO 流中,然后我想将其添加到 pdf 页面,然后将 pdf 文件作为附件发送到电子邮件中:

import matplotlib.pyplot as plt
import io
from fpdf import FPDF

fig = plt.figure()
...
buf = io.BytesIO()
fig.savefig(buf, format='png')

pdf = FPDF()
pdf.add_page()
pdf.image(buf.getvalue(), type='PNG')
buf.close()
Run Code Online (Sandbox Code Playgroud)

但这不起作用,并报告以下错误:

Traceback (most recent call last):
  File "XXXX.py", line 166, in send_email
    pdf.image(buf.getvalue(), type='PNG')
  File "/usr/local/lib/python3.6/site-packages/fpdf/fpdf.py", line 150, in wrapper
    return fn(self, *args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/fpdf/fpdf.py", line 971, in image
    info=self._parsepng(name)
  File "/usr/local/lib/python3.6/site-packages/fpdf/fpdf.py", line 1769, in _parsepng
    if name.startswith("http://") or name.startswith("https://"):
TypeError: startswith first arg …
Run Code Online (Sandbox Code Playgroud)

io matplotlib fpdf python-3.x pandas

5
推荐指数
1
解决办法
2248
查看次数

How should I scipy.optimize a multivariate and non-differentiable function with boundaries?

I come upon the following optimization problem:

The target function is a multivariate and non-differentiable function which takes as argument a list of scalars and return a scalar. It is non-differentiable in the sense that the computation within the function is based on pandas and a series of rolling, std, etc. actions.

The pseudo code is below:

def target_function(x: list) -> float:
    # calculations
    return output
Run Code Online (Sandbox Code Playgroud)

Besides, each component of the x argument has its own bounds defined as a …

python optimization scipy python-3.x

5
推荐指数
1
解决办法
5019
查看次数

标签 统计

python-3.x ×2

fpdf ×1

io ×1

matplotlib ×1

optimization ×1

pandas ×1

python ×1

scipy ×1