8000 [Bug]: pylance (in vscode) detect error that should not detect in matplotlib (3d) · Issue #27482 · matplotlib/matplotlib · GitHub {"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Bug]: pylance (in vscode) detect error that should not detect in matplotlib (3d) ","articleBody":"### Bug summary\n\nHi 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). \r\nI am getting the following error from Pylance:\r\n\r\nCannot access member \"bar3d\" for type \"Axes\" Member \"bar3d\" is unknown\r\n\r\nCannot access member \"set_zlabel\" for type \"Axes\" Member \"set_zlabel\" is unknown\r\n\r\nIt seems like doing\r\n`ax = cast(Axes3D, fig.add_subplot(projection='3d'))`\r\nsolves the problem, but I would like to avoid that, as it is unnatural.\r\nIt seems that is related to: the stub for add_subplot would likely need an overload for the literal of `projection='3d'` (check https://github.com/microsoft/pyright/issues/6690#issuecomment-1847919732)\r\n\r\n\n\n### Code for reproduction\n\n```python\nimport matplotlib.pyplot as plt\r\nimport numpy as np\r\n\r\nx = [74, 74, 74, 74, 74, 74, 74, 74, 192, 74]\r\ny = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\r\nz = np.zeros(10)\r\ndx = np.ones(10)*10\r\ndy = np.ones(10)\r\ndz = [1455, 1219, 1240, 1338, 1276, 1298, 1292, 1157, 486, 1388]\r\n\r\nfig = plt.figure()\r\nax = fig.add_subplot(projection='3d')\r\n\r\nbar3d = ax.bar3d(x, y, z, dx, dy, dz, color='C0')\r\n\r\nax.set_title(\"Data Analysis \")\r\nax.set_xlabel('x')\r\nax.set_ylabel('y')\r\nax.set_zlabel('z')\r\n\r\nplt.show()\n```\n\n\n### Actual outcome\n\nCode with errors highlighted.\n\n### Expected outcome\n\nCode without errors\n\n### Additional information\n\n_No response_\n\n### Operating system\n\nArch\n\n### Matplotlib Version\n\n3.8.1-1\n\n### Matplotlib Backend\n\n_No response_\n\n### Python version\n\n3.11.6\n\n### Jupyter version\n\n_No response_\n\n### Installation\n\nNone","author":{"url":"https://github.com/victorballester7","@type":"Person","name":"victorballester7"},"datePublished":"2023-12-09T07:54:23.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/27482/matplotlib/issues/27482"}
[go: up one dir, main page]

Skip to content

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

@victorballester7

Description

@victorballester7

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0