Skip to content

Fix rcParams validator for dashes. #17443

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

Merged
merged 1 commit into from
May 20, 2020
Merged

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented May 18, 2020

Valid dash-patterns are actually just lists of floats:

rcParams["lines.dashed_pattern"] = (1, None)
plt.plot([1, 2], ls="--")

throws

TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@timhoffm
Copy link
Member

timhoffm commented May 18, 2020

(None, None) specifically is allowed and causes the test failure; c.f.

if seq == (None, None) or len(seq) == 0:

Semi-OT: More generally, dashes is redundant with linestyle. It's really just

    def set_dashes(self, seq):
        if seq == (None, None) or len(seq) == 0:
            self.set_linestyle('-')
        else:
            self.set_linestyle((0, seq))

I would be +0.5 deprecating dashes (or at least discouraging it's use in favor of linestyle). Additionally, one could support a simple sequence as a linestyle, which would imply zero offset; i.e. linestyle=(0, (1, 2, 1, 3)) would be equivalent to linestyle=(1, 2, 1, 3). This would allow linestyle to accept the format that dashes currently uses.

Valid dash-patterns are actually just lists of floats:
```
rcParams["lines.dashed_pattern"] = (1, None)
plt.plot([1, 2], ls="--")
```
throws
```
TypeError: unsupported operand type(s) for +: 'float' and 'NoneType'
```
@anntzer
Copy link
Contributor Author

anntzer commented May 18, 2020

It's allowed but doesn't actually work:

gca().set_prop_cycle("dashes", [[None, None]]); plot([1, 2])

fails with "TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'". (This is because what goes in the cycle is just the ink lengths, not the offset.)
Supporting offsets here would be another PR.
Edited the test accordingly.

@tacaswell tacaswell added this to the v3.3.0 milestone May 20, 2020
@timhoffm timhoffm merged commit db783f7 into matplotlib:master May 20, 2020
@anntzer anntzer deleted the dash-validator branch May 20, 2020 14:07
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.

3 participants