Skip to content

BUG: addresses #14855 by fixing color kwarg conflict #14871

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

Conversation

alexandercbooth
Copy link
Contributor

@codecov-io
Copy link

codecov-io commented Dec 13, 2016

Codecov Report

Merging #14871 into master will decrease coverage by 0.02%.
The diff coverage is 50%.

@@            Coverage Diff             @@
##           master   #14871      +/-   ##
==========================================
- Coverage   91.01%   90.99%   -0.03%     
==========================================
  Files         143      143              
  Lines       49400    49399       -1     
==========================================
- Hits        44963    44952      -11     
- Misses       4437     4447      +10
Impacted Files Coverage Δ
pandas/tools/plotting.py 71.75% <50%> (-0.02%) ⬇️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/common.py 90.96% <0%> (-0.34%) ⬇️
pandas/core/frame.py 97.86% <0%> (-0.1%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 9d3554c...3245f09. Read the comment docs.

kwds.setdefault('c', plt.rcParams['patch.facecolor'])
if 'color' in kwds:
pass
else:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kwds.setdefault('c', kwdgs.pop('color', plt.rcParams['patch.facecolor'])) is a big more idiomatic

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm, I see that these kwards are slightly different. Can you update / add to the comment (and reference the issue).

@jreback
Copy link
Contributor

jreback commented Dec 13, 2016

pls add a whatsnew note (for 0.19.2 is fine)

@jreback jreback added the Visualization plotting label Dec 13, 2016
@jreback
Copy link
Contributor

jreback commented Dec 13, 2016

pls add a test

@@ -359,7 +359,10 @@ def scatter_matrix(frame, alpha=0.5, figsize=None, ax=None, grid=False,
density_kwds = density_kwds or {}

# workaround because `c='b'` is hardcoded in matplotlibs scatter method
kwds.setdefault('c', plt.rcParams['patch.facecolor'])
if 'color' in kwds:
Copy link
Member

@sinhrks sinhrks Dec 14, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't overwrite if either ‘c’, ‘color’ or ‘facecolor’ is specified.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry, I don't quite understand. Could you explain a little bit more?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant, plt.scatter(..., facecolor='red') and plt.scatter(..., c='red') both draws points in red. So scatter_matrix(..., facecolor='red') and scatter_matrix(..., c='red') should be the same.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh gotcha. Thanks!
So one of the problems turned out that difference between c and color was an edge border on the markers. We can take care of that by setting the default to 'none'. After making the changes here is the current behavior:
image
image
image
All are now the same.

@alexandercbooth
Copy link
Contributor Author

Sorry for the slow response, long week at work. Thank you both for the feedback, let me know if there's something else I can change.

@alexandercbooth
Copy link
Contributor Author

I also notice that this exact same bug is present in scatter_plot. It can be fixed in exactly the same way as I have done above:

image
image
image

I would be happy to fix it as well. I could just tack it on here or open another PR, whichever is best.

if 'facecolor' in kwds:
kwds.setdefault('facecolor', plt.rcParams['patch.facecolor'])
if 'c' in kwds:
kwds.setdefault('c', plt.rcParams['patch.facecolor'])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not understand this, if 'c' is in kwds, then setdefault is a no-op.

You probably also want to version guard this, mpl 2.0 scatter respects the color cycle
http://matplotlib.org/2.0.0rc1/users/dflt_style_changes.html#scatter

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good thinking, @tacaswell! I investigated it a bit further and it turns out we can resolve this issue and the same issue for scatter_plot by removing the old bug fix, removing the new changes and adding in the edgecolor='none' as default. With this, we still get the identical behavior with c, color or facecolor set and no error.

@tacaswell
Copy link
Contributor

The change to the default value of c went in via matplotlib/matplotlib#4079 which is in mpl >=1.5.0. pandas will need to do some version checking to correctly support older versions of mpl. I thought back to 1.3.1 is currently supported?

@jreback
Copy link
Contributor

jreback commented Dec 30, 2016

status of this?

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work (I don't fully understand how passing facecolor solves the color cs c conflict).
The only thing is that this slightly changes the plot appearance. As previously c only changed the facecolor, while it now also seems to change the edgecolor.

@@ -80,3 +80,6 @@ Bug Fixes
- Explicit check in ``to_stata`` and ``StataWriter`` for out-of-range values when writing doubles (:issue:`14618`)

- Bug in ``unstack()`` if called with a list of column(s) as an argument, regardless of the dtypes of all columns, they get coerced to ``object`` (:issue:`11847`)

- Bug in ``pd.scatter_matrix()`` could accept either ``color`` or ``c``, but
not both (:issue:`14855`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move this to 0.20.0.txt?

@@ -77,6 +77,12 @@ def scat(**kwds):
_check_plot_works(scat, diagonal='hist')
with tm.assert_produces_warning(UserWarning):
_check_plot_works(scat, range_padding=.1)
with tm.assert_produces_warning(UserWarning):
_check_plot_works(scat, color='rgb')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you pass here 'rgb' and not just 'r'? As passing multiple colors seems a bit odd for a single scatter plot (I think now the points just get the [r, g, b, r, g, b, r, g, b, ...] colors sequentially?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Purely for aesthetic purposes. I have trouble seeing some colors and wanted to visually confirm these changes rendered the same objects.

@jreback
Copy link
Contributor

jreback commented Jan 21, 2017

status on this? @sinhrks @jorisvandenbossche @TomAugspurger

@jreback jreback added this to the 0.20.0 milestone Jan 21, 2017
@alexandercbooth
Copy link
Contributor Author

Thanks Jeff and everyone else for your patience on this; it's been a really hectic month at work. I appreciate all the feedback from everyone. I will try to address all concerns I can tomorrow and report back.
Thanks!

@alexandercbooth
Copy link
Contributor Author

I squashed and rebased since the PR was stale, but it's my first time doing that so I apologize if I made a mistake.

@jreback
Copy link
Contributor

jreback commented Mar 23, 2017

@alexandercbooth can you rebase

@TomAugspurger ok on this?

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
@alexandercbooth alexandercbooth force-pushed the fix-color-scatterm-bug branch from aa07157 to 3245f09 Compare March 23, 2017 20:50
@jreback
Copy link
Contributor

jreback commented Mar 23, 2017

lgtm. @TomAugspurger ok? (don't merge yet)

@jreback
Copy link
Contributor

jreback commented Mar 25, 2017

@TomAugspurger ?

@TomAugspurger
Copy link
Contributor

Sorry for the delay, +1 on this.

@jreback, when you merge PRs that need a rebase (conflicts in whatsnew), you use the merge-pr.py script, right? I can do it, just want to double check first. Don't want to make @alexandercbooth rebase again.

@jreback
Copy link
Contributor

jreback commented Apr 5, 2017

@TomAugspurger yes you can use the script. it will stop when it can't auto rebase (it will squash), you then fix the conflicts, git add, then continue the script. Then I stop again (its now rebased), just to make sure the commits message and everything is ok. Then have it push upstream.

@TomAugspurger
Copy link
Contributor

@alexandercbooth thanks!

@alexandercbooth
Copy link
Contributor Author

My pleasure!

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 this pull request may close these issues.

scatter_matrix color vs c
7 participants