Skip to content

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

@sdschmidt

Description

@sdschmidt

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy