question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Meaning of color argument in DataFrame.plot.scatter()

See original GitHub issue

Code Sample, a copy-pastable example if possible

df = pd.DataFrame.from_records([[1,1,'g'],[2,2,'r']], columns=['x','y','Color'])
df.plot.scatter(x='x',y='y',c='Color')

Problem description

The issue here is that it is not clear what the values in the column corresponding to the argument c of scatter should be. The example given at http://pandas.pydata.org/pandas-docs/stable/visualization.html#scatter-plot uses numerical values, but in this example, I just want red and green dots. With matplotlib, you can supply the colors as a vector.

IMHO, the API should be consistent. You should be able to specify the column names corresponding to the value of x, y, and the color. This would be especially useful if you have a pattern such as:

df[df.x>=1].plot.scatter(x='x', y='y', c='Color')

where you produce a scatter plot of selected rows.

The code in the simple example generates an error:

KeyError                                  Traceback (most recent call last)
C:\Anaconda3\envs\py36\lib\site-packages\matplotlib\colors.py in to_rgba(c, alpha)
    140     try:
--> 141         rgba = _colors_full_map.cache[c, alpha]
    142     except (KeyError, TypeError):  # Not in cache, or unhashable.

KeyError: ('o', None)

Expected Output

A plot with 2 points, one red and one green.

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.1.final.0 python-bits: 64 OS: Windows OS-release: 10 machine: AMD64 processor: Intel64 Family 6 Model 60 Stepping 3, GenuineIntel byteorder: little LC_ALL: None LANG: None LOCALE: None.None

pandas: 0.20.1 pytest: None pip: 9.0.1 setuptools: 27.2.0 Cython: None numpy: 1.12.1 scipy: None xarray: None IPython: 6.0.0 sphinx: None patsy: None dateutil: 2.6.0 pytz: 2017.2 blosc: None bottleneck: None tables: None numexpr: None feather: None matplotlib: 2.0.0 openpyxl: None xlrd: 1.0.0 xlwt: None xlsxwriter: None lxml: None bs4: None html5lib: 0.999 sqlalchemy: None pymysql: None psycopg2: None jinja2: 2.9.6 s3fs: None pandas_gbq: None pandas_datareader: None

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
jorisvandenbosschecommented, Jun 27, 2017

@amichaut I think this is fixed on master, see https://github.com/pandas-dev/pandas/issues/16695 (and PR https://github.com/pandas-dev/pandas/pull/16701). This will probably be released in 0.20.3

1reaction
VincentLacommented, May 24, 2017

Oh interesting, I might try to see if I can pick this up

Read more comments on GitHub >

github_iconTop Results From Across the Web

pandas.DataFrame.plot.scatter — pandas 0.25.3 documentation
Create a scatter plot with varying marker point size and color. The coordinates of each point are defined by two dataframe columns and...
Read more >
Matplotlib Scatter Plot Color by Category in Python - Kanoki.org
The hue parameter is used for Grouping variable that will produce points with different colors. Can be either categorical or numeric, although ...
Read more >
Set the color for scatter-plot with DataFrame.plot
The c argument of pandas.DataFrame.plot is in this case passed through literally so everything will have the color 'c' (cyan).
Read more >
Pandas Scatter Plot – DataFrame.plot.scatter()
Scatter Parameters · Single color – Either a hex string '#b31d59' or 'red' · Array of colors – Setting your data points alternating...
Read more >
Scatter plots in Python
Over 26 examples of Scatter Plots including changing color, size, ... x and y given as DataFrame columns import plotly.express as px df...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found