-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Description
Bug summary
Hi everyone! I'm in VSCode and I have the extension from Microsoft for Python. I have the following error. Consider the following code without errors (a priori).
I am getting the following error from Pylance:
Cannot access member "bar3d" for type "Axes" Member "bar3d" is unknown
Cannot access member "set_zlabel" for type "Axes" Member "set_zlabel" is unknown
It seems like doing
ax = cast(Axes3D, fig.add_subplot(projection='3d'))
solves the problem, but I would like to avoid that, as it is unnatural.
It seems that is related to: the stub for add_subplot would likely need an overload for the literal of projection='3d'
(check microsoft/pyright#6690 (comment))
Code for reproduction
import matplotlib.pyplot as plt
import numpy as np
x = [74, 74, 74, 74, 74, 74, 74, 74, 192, 74]
y = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
z = np.zeros(10)
dx = np.ones(10)*10
dy = np.ones(10)
dz = [1455, 1219, 1240, 1338, 1276, 1298, 1292, 1157, 486, 1388]
fig = plt.figure()
ax = fig.add_subplot(projection='3d')
bar3d = ax.bar3d(x, y, z, dx, dy, dz, color='C0')
ax.set_title("Data Analysis ")
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('z')
plt.show()
Actual outcome
Code with errors highlighted.
Expected outcome
Code without errors
Additional information
No response
Operating system
Arch
Matplotlib Version
3.8.1-1
Matplotlib Backend
No response
Python version
3.11.6
Jupyter version
No response
Installation
None