1 | initial version |
The recommended method to indicate the data type of a matplotlib Figure object in Python3 using type hints is:
import matplotlib.figure as fig
from typing import TypeVar
Figure = TypeVar('fig.Figure')
Then, you can use Figure
as the data type annotation for any variable or function parameter that expects a Matplotlib Figure object. For example, if you have a function that takes a Matplotlib Figure object and a NumPy array as inputs and returns a Matplotlib Figure object as output, you could write:
import numpy as np
def plot_data(fig: Figure, data: np.ndarray) -> Figure:
# code to plot data on the figure
return fig
This indicates that the fig
parameter should be a Matplotlib Figure object, the data
parameter should be a NumPy array, and the function should return a Matplotlib Figure object.