Skip to content

Customised dashed linstyle in matplotlib.cycler throws ValueError when using in Axes.set_prop_cycle #15825

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

Closed
sdschmidt opened this issue Dec 3, 2019 · 0 comments · Fixed by #15827

Comments

@sdschmidt
Copy link

sdschmidt commented Dec 3, 2019

Bug report

Bug summary

Using a cycler from matplotlib with a customised dashed linestyle for the property cycle in Axes.set_prop_cycle throws a ValueError (see below). Importing cycler from cycler works as expected.

Code for reproduction

import matplotlib.pyplot as plt
from matplotlib import rcParams
from matplotlib import cycler # from cycler import cycler works fine

cc = cycler('linestyle', [(0,(3,1)), '-'])

fig = plt.figure()
ax = fig.add_subplot(221)
ax.set_prop_cycle(cc)
ax.plot(range(10))

Actual outcome

Traceback (most recent call last):
  File "err.py", line 10, in <module>
    ax.plot(range(10))
  File "/usr/local/lib/python3.7/site-packages/matplotlib/axes/_axes.py", line 1665, in plot
    lines = [*self._get_lines(*args, data=data, **kwargs)]
  File "/usr/local/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 225, in __call__
    yield from self._plot_args(this, kwargs)
  File "/usr/local/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 405, in _plot_args
    seg = func(x[:, j % ncx], y[:, j % ncy], kw, kwargs)
  File "/usr/local/lib/python3.7/site-packages/matplotlib/axes/_base.py", line 312, in _makeline
    seg = mlines.Line2D(x, y, **kw)
  File "/usr/local/lib/python3.7/site-packages/matplotlib/lines.py", line 377, in __init__
    self.set_linestyle(linestyle)
  File "/usr/local/lib/python3.7/site-packages/matplotlib/lines.py", line 1186, in set_linestyle
    cbook._check_in_list([*self._lineStyles, *ls_mapper_r], ls=ls)
  File "/usr/local/lib/python3.7/site-packages/matplotlib/cbook/__init__.py", line 2170, in _check_in_list
    .format(v, k, ', '.join(map(repr, values))))
ValueError: '(0, (3, 1))' is not a valid value for ls; supported values are '-', '--', '-.', ':', 'None', ' ', '', 'solid', 'dashed', 'dashdot', 'dotted'

Expected outcome

I would expect matplotlib.cycler to work the same as cycler.cycler. However, in this case matplotlib.cycler throws a ValueError.

Matplotlib version

  • Operating system: macOS Mojave 10.14.6
  • Matplotlib version: 3.1.2
  • Matplotlib backend (print(matplotlib.get_backend())): MacOSX
  • Python version: 3.7.4
  • Jupyter version (if applicable): --
  • Other libraries: --

matplotlib installed via pip

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