X Tutup
Skip to content

New axes.set_prop_cycle method cannot handle any generic iterable #5368

@u55

Description

@u55

Dear matplotlib developers,

The docstring for the new method axes.set_prop_cycle, says that it can take any iterable for the property value. However, I found that it fails with a ValueError if given a numpy.ndarray. Here is a minimal working example:

from __future__ import print_function
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm

cmap = cm.Set1(np.linspace(0,1,9))
print(type(cmap),'\n')

fig, ax = plt.subplots()
ax.set_prop_cycle('color', cmap.tolist())    # works
ax.set_prop_cycle('color', cmap)    # raises ValueError
plt.show()

which produces this traceback:

<type 'numpy.ndarray'> 

Traceback (most recent call last):
  File "/tmp/untitled.py", line 12, in <module>
    ax.set_prop_cycle('color', cmap)    # raises ValueError
  File "/usr/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 1112, in set_prop_cycle
    prop_cycle = cycler(*args, **kwargs)
  File "/usr/lib/python2.7/site-packages/matplotlib/rcsetup.py", line 720, in cycler
    vals = validator(vals)
  File "/usr/lib/python2.7/site-packages/matplotlib/rcsetup.py", line 90, in f
    raise ValueError(msg)
ValueError: 's' must be of type [ string | list | tuple ]

Tested with matplotlib 1.5.0, python 2.7 and python 3.5, running in Arch Linux.
This failure in matplotlib 1.5.0 also affects the method axes.set_color_cycle, which is supposed to be deprecated but raises a ValueError instead. The following code worked in matplotlib 1.4.3 but fails in 1.5.0:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm

cmap = cm.Set1(np.linspace(0,1,9))

fig, ax = plt.subplots()
ax.set_color_cycle(cmap)    # raises ValueError
plt.show()

I think that, for convenience and for backwards compatibility with prior versions of axes.set_color_cycle, the new method axes.set_prop_cycle should be able to take any iterable, as the documentation suggests, and not be limited to only a string, list, or tuple.

Thank you,

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup