Skip to content

FIX: Keep a dash-tuple linestyle when the figure options dialog is ac… - #32358

Open
kunalKumar-13 wants to merge 1 commit into
matplotlib:mainfrom
kunalKumar-13:fix/31289-figureoptions-dash-tuple
Open

kunalKumar-13 wants to merge 1 commit into
matplotlib:mainfrom
kunalKumar-13:fix/31289-figureoptions-dash-tuple

Conversation

@kunalKumar-13

Copy link
Copy Markdown

…cepted

Line2D stores a dash tuple in _unscaled_dash_pattern and reports '--' from get_linestyle, so the Line style combobox cannot represent one. figureoptions read that name into the combobox and wrote it straight back on OK, and set_linestyle('--') replaces the custom pattern with the default dashed one. Opening the dialog and clicking OK without touching anything was enough to lose it.

Each of the four patterns from the report collapses the same way:

(0, (1, 10))              -> (0.0, (3.7, 1.6))
(5, (10, 3))              -> (0.0, (3.7, 1.6))
(0, (3, 10, 1, 10))       -> (0.0, (3.7, 1.6))
(0, (3, 5, 1, 5, 1, 5))   -> (0.0, (3.7, 1.6))

Remember what each combobox started on and only apply the selection when it differs, so an untouched combobox leaves the line alone. Comparing against the value prepare_data put at the head of the list rather than against get_linestyle, since that is what the combobox actually starts on and the two are not always spelled the same.

A line whose style really is '--' is unaffected: its dash pattern is already the default, so skipping the write changes nothing. Picking a different entry still applies as before. The one thing this gives up is deliberately selecting Dashed on a line that already has a custom pattern, which the dialog cannot express anyway - the combobox reads Dashed in both cases.

Closes #31289

PR summary

AI Disclosure

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • New and changed code is tested
  • Plotting related features are demonstrated in an example
  • New features and API changes have release notes
  • Documentation complies with general and docstring guidelines

…cepted

Line2D stores a dash tuple in _unscaled_dash_pattern and reports '--' from
get_linestyle, so the Line style combobox cannot represent one. figureoptions
read that name into the combobox and wrote it straight back on OK, and
set_linestyle('--') replaces the custom pattern with the default dashed one.
Opening the dialog and clicking OK without touching anything was enough to
lose it.

Each of the four patterns from the report collapses the same way:

    (0, (1, 10))              -> (0.0, (3.7, 1.6))
    (5, (10, 3))              -> (0.0, (3.7, 1.6))
    (0, (3, 10, 1, 10))       -> (0.0, (3.7, 1.6))
    (0, (3, 5, 1, 5, 1, 5))   -> (0.0, (3.7, 1.6))

Remember what each combobox started on and only apply the selection when it
differs, so an untouched combobox leaves the line alone. Comparing against
the value prepare_data put at the head of the list rather than against
get_linestyle, since that is what the combobox actually starts on and the two
are not always spelled the same.

A line whose style really is '--' is unaffected: its dash pattern is already
the default, so skipping the write changes nothing. Picking a different entry
still applies as before. The one thing this gives up is deliberately
selecting Dashed on a line that already has a custom pattern, which the
dialog cannot express anyway - the combobox reads Dashed in both cases.

Closes matplotlib#31289
@github-actions

Copy link
Copy Markdown

Thank you for opening your first PR into Matplotlib!

If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks. We also ask that you please finish addressing any review comments on this PR and wait for it to be merged (or closed) before opening a new one, as it can be a valuable learning experience to go through the review process.

You can also join us on discourse chat for real-time discussion.

For details on testing, writing docs, and our review process, please see the developer guide.
Please let us know if (and how) you use AI, it will help us give you better feedback on your PR.

We strive to be a welcoming and open project. Please follow our Code of Conduct.

@iccir

iccir commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Hello, please review our AI policy and fill out the original Pull Request Template to let us know about your use of AI. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: QtAgg backend does not preserve linestyles refined by dash tuples after editing parameters

2 participants