通过以下方式创建图形:'import matplot lib as mpl '和'self.figure = mpl.figure.Figure(dpi=dpi, Figsize=(2, 2))'

问题描述 投票:0回答:1

我已经使用这个语法 'self.figure = mpl.figure.Figure(dpi=dpi, Figsize=(2, 2))' 在以下条件下创建图形:Python - 3.8.6 和 Matplotlib - 3.4.1 ,效果很好。

现在我必须使用 Matplotlib - 3.7.3,这样做时我收到红色消息“AttributeError: module 'matplotlib' has no attribute 'figure'”。但事实上这个语法存在于这个版本的 Matplotlib 的文档中。

是否有任何等效或更新的函数可以替代该行?

谢谢你

sintax 在创建图形方面工作得很好,我预计在新的 Matplotlib 版本中也能工作。

matplotlib wxpython figure
1个回答
0
投票

如果您尝试从 Matplotlib 访问 figure(),那么这将失败,因为 Matplotlib 的 home 目录中不存在这样的函数。您需要进入子目录 pyplot 才能从 Matplotlib 访问figure()。因此,例如:

import matplotlib.pyplot as plt

然后你可以这样做:

fig = plt.figure()

请记住,Matplotlib.pyplot.figure() 可以与 mpl_toolkits 一起使用。

最重要的是,您无法从 Matplotlib 的主目录访问figure();您需要进入其子目录之一才能访问它。

© www.soinside.com 2019 - 2024. All rights reserved.