Skip to content

[Bug]: Args for tripcolor #22303

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
ThibaultGROUEIX opened this issue Jan 24, 2022 · 4 comments · Fixed by #22356
Closed

[Bug]: Args for tripcolor #22303

ThibaultGROUEIX opened this issue Jan 24, 2022 · 4 comments · Fixed by #22356

Comments

@ThibaultGROUEIX
Copy link

ThibaultGROUEIX commented Jan 24, 2022

Bug summary

Thanks for matplotlib!
tripcolor fails if colors are passed with named argument i.e c=values instead of just values. The error is not very informative and it seems a dangerous practice to ignore kwargs and only use args.

  File "/mnt/session_space/conda_envs/latest39/lib/python3.9/site-packages/matplotlib/tri/tripcolor.py", line 57, in tripcolor
    C = np.asarray(args[0])
IndexError: list index out of range

Code for reproduction

plt.tripcolor(vertices[:,0], vertices[:,1], c=values, triangles=triangles)

Actual outcome

  File "/mnt/session_space/conda_envs/latest39/lib/python3.9/site-packages/matplotlib/tri/tripcolor.py", line 57, in tripcolor
    C = np.asarray(args[0])
IndexError: list index out of range

Expected outcome

a successful plot.

Additional information

No response

Operating system

No response

Matplotlib Version

3.5.1

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

No response

@QuLogic
Copy link
Member

QuLogic commented Jan 25, 2022

Please provide a complete example. (Also, I don't think c is a valid keyword argument to tripcolor.)

@QuLogic QuLogic added status: needs clarification Issues that need more information to resolve. topic: pcolor/pcolormesh labels Jan 25, 2022
@jklymak
Copy link
Member

jklymak commented Jan 28, 2022

I'll close for lack of response, but do request a re-open if there is still an issue here.

@jklymak jklymak closed this as completed Jan 28, 2022
@anntzer
Copy link
Contributor

anntzer commented Jan 28, 2022

Basically tripcolor(np.random.rand(5), np.random.rand(5), C=np.random.rand(5)) currently fails with the not-so-informative error message above (the correct invocation is tripcolor(np.random.rand(5), np.random.rand(5), np.random.rand(5))). I think we should indeed not allow passing C by keyword, only positionally (see #11526 for essentially the same discussion on quiver); however the error could be made clearer.

@anntzer anntzer added API: argument checking and removed status: needs clarification Issues that need more information to resolve. labels Jan 28, 2022
@jklymak jklymak reopened this Jan 28, 2022
@timhoffm
Copy link
Member

Unfortunately, the API is heavily overloaded. We need an *args parameter that can take many forms, and we cannot get rid of it without major API breakage. Things to do:

  • Clarify which APIs we want to support
  • Improve the documentation
  • Cleanup the parameter parsing. There seem some assumptions to be baked in. Probably we should have an internal parser function triangulation, C, kwargs = parse_params(args, kwargs) that we can unittest the defined API against, and that issues reasonable warnings.

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.

5 participants