-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
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
BUG: addresses #14855 by fixing color kwarg conflict #14871
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
pandas/tools/plotting.py
Outdated
kwds.setdefault('c', plt.rcParams['patch.facecolor']) | ||
if 'color' in kwds: | ||
pass | ||
else: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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).
pls add a whatsnew note (for 0.19.2 is fine) |
pls add a test |
pandas/tools/plotting.py
Outdated
@@ -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: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
pandas/tools/plotting.py
Outdated
if 'facecolor' in kwds: | ||
kwds.setdefault('facecolor', plt.rcParams['patch.facecolor']) | ||
if 'c' in kwds: | ||
kwds.setdefault('c', plt.rcParams['patch.facecolor']) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
The change to the default value of |
status of this? |
There was a problem hiding this 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.
doc/source/whatsnew/v0.19.2.txt
Outdated
@@ -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`) |
There was a problem hiding this comment.
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') |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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.
status on this? @sinhrks @jorisvandenbossche @TomAugspurger |
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. |
da23aab
to
aa07157
Compare
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. |
@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
aa07157
to
3245f09
Compare
lgtm. @TomAugspurger ok? (don't merge yet) |
Sorry for the delay, +1 on this. @jreback, when you merge PRs that need a rebase (conflicts in whatsnew), you use the |
@TomAugspurger yes you can use the script. it will stop when it can't auto rebase (it will squash), you then fix the conflicts, |
@alexandercbooth thanks! |
My pleasure! |
color
vsc
#14855git diff upstream/master | flake8 --diff