Skip to content

scatter_matrix color vs c #14855

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

Closed
smartinsightsfromdata opened this issue Dec 11, 2016 · 1 comment
Closed

scatter_matrix color vs c #14855

smartinsightsfromdata opened this issue Dec 11, 2016 · 1 comment
Labels
Milestone

Comments

@smartinsightsfromdata
Copy link

I reported the issue below to matplotlib here, but they have requested to report it here as it appears (to the matplotlib folks) related to pandas.

The following code gives error, but works replacing color= with c=

I suspect is either a bug, or some piece of documentation missing?
(matplotlib folks think it is a pandas / scatter_matrix bug - see below)

I'm using:
matplotlib 1.5.3
pandas 0.19.1
python 3.5

This is a sample code:

import pandas as pd
import numpy as np
from sklearn.datasets import load_iris
%matplotlib inline

iris = load_iris()
colors = list()
palette = {0: "red", 1: "green", 2: "blue"}

for c in np.nditer(iris.target): colors.append(palette[int(c)])
    # using the palette dictionary, we convert
    # each numeric class into a color string
dataframe = pd.DataFrame(iris.data,
columns=iris.feature_names)
scatterplot = pd.scatter_matrix(dataframe, alpha=0.3,
figsize=(10, 10), diagonal='hist', color=colors, marker='o', grid=True)

This is the error trace:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-4-f3d30057e124> in <module>()
     14 columns=iris.feature_names)
     15 scatterplot = pd.scatter_matrix(dataframe, alpha=0.3,
---> 16 figsize=(10, 10), diagonal='hist', color=colors, marker='o', grid=True)

/Users/e/anaconda/lib/python3.5/site-packages/pandas/tools/plotting.py in scatter_matrix(frame, alpha, figsize, ax, grid, diagonal, marker, density_kwds, hist_kwds, range_padding, **kwds)
    393 
    394                 ax.scatter(df[b][common], df[a][common],
--> 395                            marker=marker, alpha=alpha, **kwds)
    396 
    397                 ax.set_xlim(boundaries_list[j])

/Users/e/anaconda/lib/python3.5/site-packages/matplotlib/__init__.py in inner(ax, *args, **kwargs)
   1817                     warnings.warn(msg % (label_namer, func.__name__),
   1818                                   RuntimeWarning, stacklevel=2)
-> 1819             return func(ax, *args, **kwargs)
   1820         pre_doc = inner.__doc__
   1821         if pre_doc is None:

/Users/e/anaconda/lib/python3.5/site-packages/matplotlib/axes/_axes.py in scatter(self, x, y, s, c, marker, cmap, norm, vmin, vmax, alpha, linewidths, verts, edgecolors, **kwargs)
   3787                 facecolors = co
   3788             if c is not None:
-> 3789                 raise ValueError("Supply a 'c' kwarg or a 'color' kwarg"
   3790                                  " but not both; they differ but"
   3791                                  " their functionalities overlap.")

ValueError: Supply a 'c' kwarg or a 'color' kwarg but not both; they differ but their functionalities overlap.

According to @goyodiaz:

It looks like a pandas issue. pandas.scatter_matrix always pass c to scatter but the caller can optionally pass more keywords arguments, including color. If the caller pass only color then scatter_matrix will pass both c and color and matplotlib will raise with a message that is confusing to the user because they did not pass c. Probably scatter_matrix should either raise with a clearer message or drop the c keyword argument when the user pass color

.

@jorisvandenbossche
Copy link
Member

Yes, this can indeed be solved on the pandas side as @goyodiaz indicated. We can just check for the user passing color as a kwarg and in that case let it replace the default c (and docs can maybe also use an update).
This should be an easy fix.

@jorisvandenbossche jorisvandenbossche added this to the Next Major Release milestone Dec 11, 2016
alexandercbooth added a commit to alexandercbooth/pandas that referenced this issue Dec 13, 2016
alexandercbooth added a commit to alexandercbooth/pandas that referenced this issue Dec 16, 2016
@jreback jreback modified the milestones: 0.20.0, Next Major Release Jan 21, 2017
alexandercbooth added a commit to alexandercbooth/pandas that referenced this issue Jan 24, 2017
DOC: add whats new entry for addressing pandas-dev#14855

TEST: add test for adding color kwarg to scatter_matrix

BUG: add comment that addresses the issue

BUG: set default edgecolor to none and fix facecolor

TST: add facecolor test

BUG: remove new changes and old bug fix
@jreback jreback modified the milestones: 0.20.0, Next Major Release Mar 23, 2017
alexandercbooth added a commit to alexandercbooth/pandas that referenced this issue Mar 23, 2017
DOC: add whats new entry for addressing pandas-dev#14855

TEST: add test for adding color kwarg to scatter_matrix

BUG: add comment that addresses the issue

BUG: set default edgecolor to none and fix facecolor

TST: add facecolor test

BUG: remove new changes and old bug fix
@jreback jreback modified the milestones: 0.20.0, Next Major Release Mar 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants