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

Add 'color' and 'size' to arguments #44856

Merged
merged 24 commits into from Apr 7, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions pandas/plotting/_core.py
Expand Up @@ -1582,7 +1582,7 @@ def pie(self, **kwargs):
raise ValueError("pie requires either y column or 'subplots=True'")
return self(kind="pie", **kwargs)

def scatter(self, x, y, s=None, c=None, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

you can deprecate but not rename as that is a breaking change

these are matpotlib names but not objecting to the change per se

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 see your point but I need some help to solve it. What is best practice in this situation and how does a deprication warning work?

Copy link
Member

Choose a reason for hiding this comment

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

@mosc9575 check some other PRs which deprecate arguments for examples https://github.com/pandas-dev/pandas/pulls?q=is%3Apr+depr+is%3Amerged+

Copy link
Contributor Author

@mosc9575 mosc9575 Dec 12, 2021

Choose a reason for hiding this comment

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

@jreback I used the wrong word. I did not "rename", I added size and color to avoid braking code.

Copy link
Member

Choose a reason for hiding this comment

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

I wouldn't keep both in the signature, that'd be confusing

I'd suggest:

  • use color and size in the signature
  • if color is None, take c from kwargs (likewise for size and s)
  • raise an error if someone passes both color and c
  • check that the docs consistently use color and size

Copy link
Contributor Author

@mosc9575 mosc9575 Dec 12, 2021

Choose a reason for hiding this comment

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

@MarcoGorelli Thank you. I go with your suggestions. I will edit my PR.

Copy link
Member

Choose a reason for hiding this comment

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

thanks - will also need tests to cover the new behaviour

def scatter(self, x, y, size=None, s=None, color=None, c=None, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be used as positional arguments and your change is not backwards compatible, best to use the order:

self, x, y, s, c, size, color, **kwargs

Copy link
Contributor

Choose a reason for hiding this comment

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

actually I misread the purpose of this PR, shouldn't we be replicating matplotlibs arguments? Can you indicate why you want to make this change?

Copy link
Member

Choose a reason for hiding this comment

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

this can be used as positional arguments

ah yes, thanks - @mosc9575 please ignore part of my previous comment

let's keep s and c in the signature then, add color and size after them, and deprecate s and c?

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 indicate why you want to make this change?

Just for consistency really, as in bar and barh it's color

Copy link
Contributor Author

@mosc9575 mosc9575 Dec 12, 2021

Choose a reason for hiding this comment

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

Can you indicate why you want to make this change?

I opend this issue, because c was not intuitive for me. I don't have the matplotlib background, I normally work with bokeh, and they have the same functionality of c named color. Then I was searching the pandas documentation and found color used for hbar and bar. Therefor I thought this is not consitent and a misstake by this function. To be honest, I first understood the naming when I looked into matplotlib today. But it is still not "intuitive" to me.

Please let me know if you think this shouldn't be changed at all.

Copy link
Contributor Author

@mosc9575 mosc9575 Dec 12, 2021

Choose a reason for hiding this comment

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

I was reading the matplotlib documentation for a while and the same problem can be found there. I will wait for a response to my issue #21795 and change both in one step, if this is approved.

Copy link
Contributor

Choose a reason for hiding this comment

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

i think we could also accept color size and and not deprecate

Copy link
Member

Choose a reason for hiding this comment

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

Yes, agreed, I'd go with:

  • keep signature as is
  • if c is None, take color from kwargs (likewise for s and size)
  • raise an error if someone passes both color and c, or size and s (and test this)

Conversely, for bar:

  • keep signature as is
  • if color is None, take c from kwargs
  • raise an error if someone passes both color and c (and test this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Matplolib won't change and I think the sugessted changes by @MarcoGorelli are good. I try to edit my PR soon.

"""
Create a scatter plot with varying marker point size and color.

Expand All @@ -1601,7 +1601,7 @@ def scatter(self, x, y, s=None, c=None, **kwargs):
y : int or str
The column name or column position to be used as vertical
coordinates for each point.
s : str, scalar or array-like, optional
size : str, scalar or array-like, optional
The size of each point. Possible values are:

- A string with the name of the column to be used for marker's size.
Expand All @@ -1614,7 +1614,7 @@ def scatter(self, x, y, s=None, c=None, **kwargs):

.. versionchanged:: 1.1.0

c : str, int or array-like, optional
color : str, int or array-like, optional
The color of each point. Possible values are:

- A single color string referred to by name, RGB or RGBA code,
Expand Down Expand Up @@ -1653,7 +1653,7 @@ def scatter(self, x, y, s=None, c=None, **kwargs):
... columns=['length', 'width', 'species'])
>>> ax1 = df.plot.scatter(x='length',
... y='width',
... c='DarkBlue')
... color='DarkBlue')

And now with the color determined by a column as well.

Expand All @@ -1662,10 +1662,10 @@ def scatter(self, x, y, s=None, c=None, **kwargs):

>>> ax2 = df.plot.scatter(x='length',
... y='width',
... c='species',
... color='species',
... colormap='viridis')
"""
return self(kind="scatter", x=x, y=y, s=s, c=c, **kwargs)
return self(kind="scatter", x=x, y=y, s=size or s, c=color or c, **kwargs)

def hexbin(self, x, y, C=None, reduce_C_function=None, gridsize=None, **kwargs):
"""
Expand Down