Skip to content
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: don't plot colorbar if c is column containing colors #34344

Merged
merged 5 commits into from
Jun 14, 2020

Conversation

MarcoGorelli
Copy link
Member

@MarcoGorelli MarcoGorelli commented May 23, 2020

Copy link
Member

@charlesdong1991 charlesdong1991 left a comment

Choose a reason for hiding this comment

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

nice PR!

btw, I would suggest change the PR name a bit based on your change here, the change is not about if c being column name or not, but the values of c will make difference in colorbar.

@@ -969,6 +966,16 @@ def _make_plot(self):
else:
c_values = c

# plot a colorbar only if a colormap is provided or necessary
Copy link
Member

Choose a reason for hiding this comment

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

maybe remove this line and add a more descriptive comment for the next line (c_is_column_not_containing_colors)? this comment does not seem to add too much value to help others understand?

# plot a colorbar only if a colormap is provided or necessary
from matplotlib.colors import is_color_like

c_is_column_not_containing_colors = c_is_column and not all(
Copy link
Member

Choose a reason for hiding this comment

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

maybe currently we should only consider if c_values are numeric, instead of checking if not all are color-like?

because your other PR are still under development, and seems no concrete conclusion on how we will show categorical/color-like in colorbar/legend, so now only having numeric values on colorbar seems most reasonable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, good point - thanks for your review, @charlesdong1991 !

pandas/tests/plotting/test_frame.py Show resolved Hide resolved
@MarcoGorelli MarcoGorelli changed the title BUG: Remove colorbar from scatterplot if c is not a column name BUG: don't plot colorbar if c is column containing colors May 25, 2020
pandas/plotting/_matplotlib/core.py Outdated Show resolved Hide resolved
Comment on lines 971 to 972
c_is_numeric_col = c_is_column and is_numeric_dtype(c_values)
cb = self.kwds.pop("colorbar", self.colormap or c_is_numeric_col)
Copy link
Member

Choose a reason for hiding this comment

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

emm, i meant something like this:

# plot colorbar if 1. colormap is assigned, 2.`c` is a column containing only numeric values
plot_colorbar = self.colormap or c_is_column
cb = self.kwds.pop("colorbar", is_numeric_dtype(c_values) and plot_colorbar)

because even when colormap is defined, if not all values of c column are numeric, we still dont want to plot colorbar, because it doesnt make sense so far. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, you're right, thanks! The way I'd originally written it there would still be a colorbar if the user passed something to cmap

@MarcoGorelli MarcoGorelli requested a review from WillAyd May 31, 2020 15:29
@@ -969,6 +967,12 @@ def _make_plot(self):
else:
c_values = c

# plot colorbar if
# 1. colormap is assigned, and
# 2.`c` is a column containing only numeric values
Copy link
Member

Choose a reason for hiding this comment

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

Do we have a test case that hits if non-numeric values are supplied? If not can you add one?

Copy link
Member Author

Choose a reason for hiding this comment

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

@WillAyd , yup, it's test_scatter_with_c_column_name_with_colors, where c='species', and the column species contains ["r", "r", "g", "g", "b"]

Copy link
Member

@WillAyd WillAyd left a comment

Choose a reason for hiding this comment

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

@WillAyd WillAyd added this to the 1.1 milestone Jun 5, 2020
@jreback jreback merged commit 98d28e3 into pandas-dev:master Jun 14, 2020
@jreback
Copy link
Contributor

jreback commented Jun 14, 2020

thanks @MarcoGorelli

@MarcoGorelli MarcoGorelli deleted the remove-colorbar-c-not-in-cols branch June 14, 2020 16:31
@mroeschke mroeschke mentioned this pull request Sep 26, 2022
5 tasks
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.

BUG: don't plot colorbar if c is column containing colors
4 participants