Skip to content

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

Description

@pawjast

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

Activity

  1. pawjast commented on Sep 15, 2023

    @pawjast
    Author

    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

  2. rcomer commented on Sep 15, 2023

    @rcomer
    Member

    (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?

  3. oscargus commented on Sep 15, 2023

    @oscargus
    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.

  4. pawjast commented on Sep 15, 2023

    @pawjast
    Author

    (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.

  5. added 2 commits that reference this issue on Dec 13, 2025
    895b200
    1ffad43
  6. added a commit that references this issue on Jan 4, 2026
    ca3a030
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions