Skip to content

[Bug/TYPE]: Scatter c Typehint does not support list of numbers when using cmap #26936

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
evgenyslab opened this issue Sep 27, 2023 · 0 comments · Fixed by #26937
Closed

[Bug/TYPE]: Scatter c Typehint does not support list of numbers when using cmap #26936

evgenyslab opened this issue Sep 27, 2023 · 0 comments · Fixed by #26937
Milestone

Comments

@evgenyslab
Copy link

Bug summary

type-checking failing when using something like this:

plt.scatter(x_coords, y_coords, c=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6], cmap='jet_r', alpha=0.6)

saying that c has incompatible types:

error: Argument "c" to "scatter" has incompatible type "list[float]"; expected "Sequence[tuple[float, float, float] | str | str | tuple[float, float, float, float] | tuple[tuple[float, float, float] | str, float] | tuple[tuple[float, float, float, float], float]] | tuple[float, float, float] | str | str | tuple[float, float, float, float] | tuple[tuple[float, float, float] | str, float] | tuple[tuple[float, float, float, float], float] | None"

However, this actually IS allowed by underlying code for plotting since c will sample from the cmap function.

I suspect this will happen in any plotting function that allows this behavior.

Code for reproduction

plt.scatter([1,2,3,4,5], [1,2,3,4,5], c=[0.1, 0.2, 0.3, 0.4, 0.5, 0.6], cmap='jet_r', alpha=0.6)

Actual outcome

mypy raises error:

error: Argument "c" to "scatter" has incompatible type "list[float]"; expected "Sequence[tuple[float, float, float] | str | str | tuple[float, float, float, float] | tuple[tuple[float, float, float] | str, float] | tuple[tuple[float, float, float, float], float]] | tuple[float, float, float] | str | str | tuple[float, float, float, float] | tuple[tuple[float, float, float] | str, float] | tuple[tuple[float, float, float, float], float] | None"

Expected outcome

mypy should not raise error

Additional information

No response

Operating system

No response

Matplotlib Version

3.8.0

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

ksunden added a commit to ksunden/matplotlib that referenced this issue Sep 27, 2023
@QuLogic QuLogic added this to the v3.8.1 milestone Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants