Skip to content

BUG: Pandas plot does not accept Columns for color keyword #44670

Closed
@mosc9575

Description

@mosc9575

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the master branch of pandas.

Reproducible Example

import pandas as pd

df = pd.DataFrame({
 'A': {1: 6, 2: 2, 3: 1, 4: 8, 5: 6},
 'B': {1: 2, 2: 10, 3: 3, 4: 1, 5: 1},
 'pos': {1: 1, 2: 2, 3: 4, 4: 1, 5: 1},
 'color': {1: 'red', 2: 'blue', 3: 'green', 4: 'red', 5: 'red'}
})

# df >>>
#    A   B  color
# 1  6   2    red
# 2  2  10   blue
# 3  1   3  green
# 4  8   1    red
# 5  6   1    red


df.plot(x='A', y='B', kind='scatter', color=df['color'].values)
# df.plot(x='A', y='B', kind='scatter', color='color')

Issue Description

I tried to plot a scatterplot with different groups, with one color for each group. I thought is is enought to pass the name of the column to the color-keyword, but this throws an error:

ValueError: 'c' argument must be a color, a sequence of colors, or a sequence of numbers, not ['color']

Expected Behavior

I expect this figure, which was generated using the commented line

s.plot(x='A', y='B', kind='scatter', color=s['color'].values)

grafik

Installed Versions

INSTALLED VERSIONS ------------------ commit : 945c9ed python : 3.9.7.final.0 python-bits : 64 OS : Linux OS-release : 5.10.0-8-amd64 Version : #1 SMP Debian 5.10.46-4 (2021-08-03) machine : x86_64 processor : x86_64 byteorder : little LC_ALL : en_US.UTF-8 LANG : en_US.UTF-8 LOCALE : en_US.UTF-8

pandas : 1.3.4
numpy : 1.20.3
pytz : 2021.1
dateutil : 2.8.2
pip : 21.2.4
setuptools : 58.0.4
Cython : 0.29.24
pytest : 6.2.5
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : 4.6.3
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : 3.0.1
IPython : 7.28.0
pandas_datareader: None
bs4 : None
bottleneck : None
fsspec : 2021.09.0
fastparquet : None
gcsfs : None
matplotlib : 3.4.3
numexpr : 2.7.3
odfpy : None
openpyxl : 3.0.7
pandas_gbq : None
pyarrow : None
pyxlsb : None
s3fs : None
scipy : 1.7.1
sqlalchemy : 1.4.23
tables : 3.6.1
tabulate : None
xarray : None
xlrd : None
xlwt : None
numba : 0.54.0
1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions