Skip to content
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

matplotlib: missing "plt.get_cmap" and "colors.rgb2hex" #1037

Closed
jli opened this issue Mar 12, 2021 · 3 comments
Closed

matplotlib: missing "plt.get_cmap" and "colors.rgb2hex" #1037

jli opened this issue Mar 12, 2021 · 3 comments
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version typestub Issue relating to our bundled type stubs

Comments

@jli
Copy link

jli commented Mar 12, 2021

Environment data

  • Language Server version: 2021.3.1
  • OS and version: darwin x64
  • Python version (and distribution if applicable, e.g. Anaconda): 3.9.2 (and matplotlib==3.3.4)
  • python.analysis.indexing: undefined
  • python.analysis.typeCheckingMode: basic

Expected behaviour

The functionsmatplotlib.pyplot.get_cmap and matplotlib.colors.rgb2hex should be recognized.

Actual behaviour

I get red squiggles.

Code Snippet / Additional information

#%%
from matplotlib import cm, colors
from matplotlib import pyplot as plt

def cmap_hex_squiggs(colormap: str, val: float) -> str:
    # "get_cmap" is not a known member of module
    cmap = plt.get_cmap(colormap)
    # "rgb2hex" is not a known member of module
    hex = colors.rgb2hex(cmap(val))
    return hex

def cmap_hex_no_squiggs(colormap: str, val: float) -> str:
    cmap = cm.get_cmap(colormap)
    hex = colors.to_hex(cmap(val))
    return hex

Upon googling, it seems like colors.rgb2hex was renamed to to_hex between matplotlib 1.5.0 and 2.0.0, and it seems like cm.get_cmap is more canonical (per https://matplotlib.org/stable/tutorials/colors/colormaps.html). But FWIW, these old/alternative names still work.

image

@jakebailey
Copy link
Member

Thanks for the report. Note that the stubs we bundle are not yet high quality enough to do strict type checking and are mainly intended to improve the completion experience (versus actually check valid code).

@jakebailey jakebailey added the typestub Issue relating to our bundled type stubs label Mar 12, 2021
@github-actions github-actions bot removed the triage label Mar 12, 2021
@jakebailey
Copy link
Member

I've added the members to colors; they weren't documented but are listed in the code as there for backwards compatibility.

get_cmap is also not documented as in pyplot and is only exported due to an import side effect, but it does appear to be there in the real code without any uses, so I'll add it too.

@jakebailey jakebailey added the fixed in next version (main) A fix has been implemented and will appear in an upcoming version label Mar 17, 2021
@jakebailey
Copy link
Member

This issue has been fixed in version 2021.3.2, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202132-17-march-2021

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in next version (main) A fix has been implemented and will appear in an upcoming version typestub Issue relating to our bundled type stubs
Projects
None yet
Development

No branches or pull requests

2 participants