Skip to content

scatter() does not accept gray strings anymore #12429

Closed

Description

@gioelelm

Bug report

Bug summary

Passing a particula gray intensity as a string seems to be broken in matplotlib 3.0, at least for the scatter() function.
This kind of argument format should (and was) possible according to documentation.

Code for reproduction

plt.scatter(np.arange(10), np.arange(10), c="0.5")

Actual outcome

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-99-426550bf20a7> in <module>()
----> 1 plt.scatter(np.arange(10), np.arange(10), c="0.5")

~/anaconda3/lib/python3.6/site-packages/matplotlib/pyplot.py in scatter(x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, data, **kwargs)
   2791         x=x, y=y, s=s, c=c, marker=marker, cmap=cmap, norm=norm,
   2792         vmin=vmin, vmax=vmax, alpha=alpha, linewidths=linewidths,
-> 2793         verts=verts, edgecolors=edgecolors, data=data, **kwargs)
   2794     sci(__ret)
   2795     return __ret

~/anaconda3/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
   1783                         "the Matplotlib list!)" % (label_namer, func.__name__),
   1784                         RuntimeWarning, stacklevel=2)
-> 1785             return func(ax, *args, **kwargs)
   1786 
   1787         inner.__doc__ = _add_data_doc(inner.__doc__,

~/anaconda3/lib/python3.6/site-packages/matplotlib/axes/_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
   4187             try:  # First, does 'c' look suitable for value-mapping?
   4188                 c_array = np.asanyarray(c, dtype=float)
-> 4189                 n_elem = c_array.shape[0]
   4190                 if c_array.shape in xy_shape:
   4191                     c = np.ma.ravel(c_array)

IndexError: tuple index out of range

Expected outcome
same as:

plt.scatter(np.arange(10), np.arange(10), c=(0.5,0.5,0.5))

Matplotlib version

  • Operating system: Linux
  • Matplotlib version: 3.0
  • Matplotlib backend (print(matplotlib.get_backend())): notebook/inline
  • Python version: 3.6 (conda, default)

Activity

  1. jklymak commented on Oct 7, 2018

    @jklymak
    Member

    Confirmed in master and also for

    import matplotlib.pyplot as plt
    import numpy as np
    
    fig, ax = plt.subplots()
    ax.scatter(np.arange(10), np.arange(10), c="0.5")
    plt.show()

    bisects to b1cd0a3 (#11383)

  2. jklymak commented on Oct 7, 2018

    @jklymak
    Member

    ping @afvincent looks like #11383 missed a case?

  3. added this to the v3.0.x milestone on Oct 7, 2018
  4. added
    Release criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
    on Oct 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    API: argument checkingValidation of acceptable argument valuesRelease criticalFor bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions