Skip to content
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

DataFrame plot method no long takes RGB tuple as color arg #16695

Closed
kjford opened this issue Jun 14, 2017 · 7 comments · Fixed by #16701
Closed

DataFrame plot method no long takes RGB tuple as color arg #16695

kjford opened this issue Jun 14, 2017 · 7 comments · Fixed by #16701
Labels
Regression Functionality that used to work in a prior pandas version Visualization plotting
Milestone

Comments

@kjford
Copy link
Contributor

kjford commented Jun 14, 2017

Problem description

The plot method on DataFrame objects takes a color argument that in versions prior to 0.20.2 took an RGB tuple as an accepted value. The 0.20.2 release throws an exception when specifying an RGB tuple for the color arg.

Code Sample

# import matplotlib.pyplot as plt
df = pandas.DataFrame([[1, 2], [3, 4]], columns=['a', 'b'])
df.plot(x='b', y='a', color=(1, 0, 0))
plt.show()

Expected Output

The expected output is a red line plot. The following exception is thrown:

Exception in Tkinter callback
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1536, in __call__
    return self.func(*args)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 280, in resize
    self.show()
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/backends/backend_tkagg.py", line 351, in draw
    FigureCanvasAgg.draw(self)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/backends/backend_agg.py", line 464, in draw
    self.figure.draw(self.renderer)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/figure.py", line 1144, in draw
    renderer, self, dsu, self.suppressComposite)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/axes/_base.py", line 2426, in draw
    mimage._draw_list_compositing_images(renderer, self, dsu)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/image.py", line 139, in _draw_list_compositing_images
    a.draw(renderer)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/artist.py", line 63, in draw_wrapper
    draw(artist, renderer, *args, **kwargs)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/lines.py", line 803, in draw
    ln_color_rgba = self._get_rgba_ln_color()
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/lines.py", line 1344, in _get_rgba_ln_color
    return mcolors.to_rgba(self._color, self._alpha)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/colors.py", line 143, in to_rgba
    rgba = _to_rgba_no_colorcycle(c, alpha)
  File "/venvs/pandas0.20.2/lib/python2.7/site-packages/matplotlib/colors.py", line 194, in _to_rgba_no_colorcycle
    raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))
ValueError: Invalid RGBA argument: 1

This plot is correctly displayed with an identical environment that has pandas 0.19.2 installed so is API breaking.

Apologies if this is fixed already in master.

Output of pd.show_versions()

NSTALLED VERSIONS ------------------ commit: None python: 2.7.10.final.0 python-bits: 64 OS: Darwin OS-release: 15.2.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

pandas: 0.20.2
pytest: None
pip: 9.0.1
setuptools: 36.0.1
Cython: None
numpy: 1.13.0
scipy: None
xarray: None
IPython: 5.4.1
sphinx: None
patsy: None
dateutil: 2.6.0
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
pandas_gbq: None
pandas_datareader: None

@kjford
Copy link
Contributor Author

kjford commented Jun 14, 2017

Follow up:
Enclosing the tuple in a list works:

df.plot(x='b', y='a', color=[(1, 0, 0)])

This looks related to #16233 which fixes #3486 but breaks what I perceive to be a fairly standard way of assigning line color (e.g. it is the first method listed for specifying color on https://matplotlib.org/users/colors.html).

@jorisvandenbossche jorisvandenbossche added Regression Functionality that used to work in a prior pandas version Visualization plotting labels Jun 14, 2017
@jorisvandenbossche jorisvandenbossche added this to the 0.20.3 milestone Jun 14, 2017
@jorisvandenbossche
Copy link
Member

@kjford Thanks for the report! That is indeed a regression, and should be fixed.

Want to do a PR to fix?

@kjford
Copy link
Contributor Author

kjford commented Jun 15, 2017

Thanks @jorisvandenbossche. See #16701.

I noticed that there are some other API inconsistencies with RGB(A) tuple handling that persist from prior versions which I chose not to address for now.

@jorisvandenbossche
Copy link
Member

Yes, that's pefect, as the other fixes should go in another PR anyway (that would not be for 0.20.3 I think).

@jxmorris12
Copy link

This is closed, but still an issue for me in pandas 0.22.0.

@jreback
Copy link
Contributor

jreback commented Dec 8, 2019

@kjford you would have to open a new issue with a reproducible example on latest version

@kjford
Copy link
Contributor Author

kjford commented Dec 9, 2019

(@jreback I think you meant that comment for @jxmorris12)

Like @jreback mentioned, @jxmorris12 can you provide a reproducible example in a new ticket? The example provided in the issue body is fixed in the latest release and I just checked 0.22.0 as well. On #16701 I commented that there are other API consistency issues that were not addressed by the fix and would require quite a bit more additional work to correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Regression Functionality that used to work in a prior pandas version Visualization plotting
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants