Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BUG: Fix scatter plot colors in groupby context to match line plot behavior (#59846)#61233

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
myenugula wants to merge5 commits intopandas-dev:main
base:main
Choose a base branch
Loading
frommyenugula:fix-issue-59846

Conversation

myenugula
Copy link
Contributor

def f(self):
return self.plot(*args, **kwargs)
# Special case for scatter plots to enable automatic colors in groupby context
if kwargs.get("kind") == "scatter":
Copy link
Member

Choose a reason for hiding this comment

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

From the issue report, this plot works withkine="line". Why do we need all this logic forscatter but it just work forline?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

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

You are right - I was trying to solve the issue as an edge case, on top of the piece that was causing this inconsistency of coloring between ScatterPlot and LinePlot.

The source of the issue is that matplotlib handles ploting both line and scatter plots. Matplotlib has its own way of color-cycling when no color is defined. Here is an example:

plt.plot([1,2,3], [1,2,3])plt.plot([4,5,6], [4,5,6])plt.plot([7,8,9], [7,8,9])# This results in having 3 different colors, one for each of the plots above

Similarly

plt.scatter(0,0)plt.scatter(1,1)plt.scatter(2,2)# This results in having 3 different colors, one for each of the points above

However, the reason for this inconsistency betweenScatterPlot andLinePlot behaviours is thatLinePlot doesn't pass any color inkwds toax.plot when calling
df.groupby("layer").plot(x='x', y='y', ax= plt.gca(), kind='line')
WhileScatterPlot explicitly defines thec= argument inax.scatter when calling
df.groupby("layer").plot(x='x', y='y', ax= plt.gca(), kind='scatter')

The solution for the source issue is to setc_values = None when no color is passed toScatterPlot; Whenself.c is None and self.color is None

Copy link
Member

Choose a reason for hiding this comment

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

Great! This is much nicer!

Copy link
Member

@rhshadrachrhshadrach left a comment

Choose a reason for hiding this comment

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

Looking good! In general, comments should only be made if they are adding new information to what the code says. A lot of comments in the test can be removed I think.

@myenugulamyenugula requested a review fromrhshadrachMay 6, 2025 13:32
@myenugula
Copy link
ContributorAuthor

I removed all unnecessary comments in the test function

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@mroeschkemroeschkeAwaiting requested review from mroeschke

@rhshadrachrhshadrachAwaiting requested review from rhshadrach

Requested changes must be addressed to merge this pull request.

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

BUG: Automatic change of color when the plot type is "line" but not when it is "scatter"
2 participants
@myenugula@rhshadrach

[8]ページ先頭

©2009-2025 Movatter.jp