如何在Python3中键入提示matplotlib图对象



我试图添加由plot .subplots返回的数据类型提示。这对plt来说很好。坐标轴,但我似乎找不到解决图的方法。

你知道我该怎么做吗?

我的代码的缩写版本是:

def draw_graph() -> Tuple[plt.Figure, plt.Axes]: 
fig, ax = plt.subplots(figsize=(14,10))
return (fig, ax)

我得到消息:"数字"不是Pylance模块的已知成员

使用最新的Matplotlib (v3.7.1),我能够执行以下操作:

import matplotlib.pyplot as plt
import matplotlib.figure
def draw_graph() -> Tuple[matplotlib.figure.Figure, plt.Axes]: 
fig, ax = plt.subplots(figsize=(14,10))
return (fig, ax)

我没有使用plt.Figure进行测试,但我的IDE(即VS Code)没有给我plt.Figure的任何错误。

最新更新