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

[Bug]: set_ticks provides mysterious error message #26283

Closed
jklymak opened this issue Jul 10, 2023 · 1 comment · Fixed by #26285
Closed

[Bug]: set_ticks provides mysterious error message #26283

jklymak opened this issue Jul 10, 2023 · 1 comment · Fixed by #26285

Comments

@jklymak
Copy link
Member

jklymak commented Jul 10, 2023

Bug summary

set_yticks(ticks, which="minor") errors with ValueError: labels argument cannot be None when kwargs are passed.

Code for reproduction

fig, ax = plt.subplots(figsize=(5.4, 5.4), layout='constrained')
x = np.arange(100)
for nn, ax in enumerate(axs):
    ax.plot(x, x)
    ax.set_yticks(np.arange(0, 100.1, 100/3))
    ax.set_yticks(np.arange(0, 100.1, 100/30), which='minor')

Actual outcome

ValueError: labels argument cannot be None when kwargs are passed

Expected outcome

Two issues here: which='minor' is incorrect for set_yticks, I should have done minor=True. It's a bit annoying that which is the kwarg for some things and minor for set_yticks.

Second, the error message is somewhat annoying as I would have expected this call to work or give me an error for an incorrect kwarg.

Additional information

No response

Operating system

No response

Matplotlib Version

main

Matplotlib Backend

No response

Python version

No response

Jupyter version

No response

Installation

None

timhoffm added a commit to timhoffm/matplotlib that referenced this issue Jul 10, 2023
@timhoffm
Copy link
Member

timhoffm commented Jul 10, 2023

This is a side-effect of #24334.

The error message is technically correct. You are doing two wrong things at the same time:

  • Use an invalid kwarg.
  • Use a kwarg without labels. (kwargs are supposed to be passed to labels)

There's no obvious choice which error should get checked first. I suppose you would be less surprised for an (incorrect) kwarg intended to modify tick labels, set_xticks(ticks, textcolor='red'). The situation looks a bit more mysterious because you have chosen a kwarg name that's a synonym to the valid minor.

I suggest to change the exception message to

Incorrect use of keyword argument 'which'. Keyword arguments other than 'minor' modify the text labels and can only be passed if 'labels' are passed as well.

This should make the error more clear. -> PR incoming.

Note that we cannot easily check whether kwargs would be valid because we just pass them on to set_ticklabels (which we can't if the user has not given tick labels. Anyway the above wording should do.

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