8000 [Bug]: pylance (in vscode) detect error that should not detect in matplotlib (3d) · Issue #27482 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

[Bug]: pylance (in vscode) detect error that should not detect in matplotlib (3d) #27482

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
victorballester7 opened this issue Dec 9, 2023 · 2 comments

Comments

@victorballester7
Copy link

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

@rcomer
Copy link
Member
rcomer commented Dec 9, 2023

I believe this is ultimately the same problem as discussed in #27455, and in particular the advice at #27455 (comment) also applies here. That is, your existing use of cast is likely the best option, at least for now.

@victorballester7
Copy link
Author

Ok, thank you! I close the issue!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0