Home > OS >  Precise type annotating array (numpy.ndarray) of matplotlib Axes from plt.subplots()
Precise type annotating array (numpy.ndarray) of matplotlib Axes from plt.subplots()

Time:06-21

I wanted to have no errors while using VSCode Pylance type checker.

How to type the axs correctly in the following code:

import matplotlib.pyplot as plt
fig, axs = plt.subplots(2, 2)

In the image below, you can see that Pylance on VSCode is detecting an error.

enter image description here

CodePudding user response:

It turns out that strongly typing the axs variable is not straightforward at all and requires to understant well how to type np.ndarray.

See enter image description here

  • Related