Skip to content

[Doc]: .set_linestyle() tuple method is unclear #26784

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

Open
pawjast opened this issue Sep 15, 2023 · 4 comments · May be fixed by #23056
Open

[Doc]: .set_linestyle() tuple method is unclear #26784

pawjast opened this issue Sep 15, 2023 · 4 comments · May be fixed by #23056

Comments

@pawjast
Copy link

pawjast commented Sep 15, 2023

Documentation Link

https://matplotlib.org/stable/api/_as_gen/matplotlib.patches.Patch.html#matplotlib.patches.Patch.set_linestyle

Problem

I looked up a method for setting plot's spine line style to a custom dash and my lazy eye caught what I highlighted in yellow:

image

I tried this and naturally I got an error:

image

Only after googling some example and reading the doc very carefully I noticed the correct way to change the line style:

image

Suggested improvement

I think the doc should be re-written so it's more explicit:

Alternatively a dash tuple of the following form can be provided:

(offset, (off_ink, on_ink))

Where:

  • offset: definition
  • on_ink/off_ink: definition
@pawjast
Copy link
Author

pawjast commented Sep 15, 2023

Also, the line object has a method set_dashes() and I wonder if it's a viable option to add a similar method to the spine object.

https://matplotlib.org/stable/gallery/lines_bars_and_markers/line_demo_dash_control.html

@rcomer
Copy link
Member

rcomer commented Sep 15, 2023

(offset, (on_ink, off_ink))

I think this would not be quite right as it seems to imply only a length 2 on-off pattern, whereas any even number should work. The linestyles example explains things pretty well, so possibly a good way to improve here is to just link the example from the docstring?

@oscargus
Copy link
Member

There is a PR which deals with most of these things that hopefully will be merged for 3.9: #23056

(The discussions are really about what get_linestyle and get_dashes should return, as that is currently inconsistent between classes and unifying it will probably break some code somewhere.)

For the original issue: yes, it is maybe unclear, but correct. Probably it can be clarified a bit further in the PR above, but it does link to the example @rcomer pointed out.

An additional challenge here is that set_dashes only takes the on-off-seq-part so it is not possible to change offset later.

@oscargus oscargus linked a pull request Sep 15, 2023 that will close this issue
6 tasks
@pawjast
Copy link
Author

pawjast commented Sep 15, 2023

(offset, (on_ink, off_ink))

I think this would not be quite right as it seems to imply only a length 2 on-off pattern, whereas any even number should work. The linestyles example explains things pretty well, so possibly a good way to improve here is to just link the example from the docstring?

I haven't seen this page before. Thanks for sharing. And yes, I think having this page linked in the doc would help as well.

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