question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Scatterplot (and possibly others?) fail when specifying a color list manually

See original GitHub issue

Matplotlib’s scatterplot allows to manually specify the color for each dot. From the documentation of seaborn.scatterplot, I see that additional kwargs should be passed on to matplotlib’s scatterplot, i.e., I should be able to set that color list.

However, here is a minimal example that leads to a crash:

import pandas as pd
import seaborn as sns

data = [{"x": x, "y": y} for x in range (0,5) for y in range(0,5)]
df = pd.DataFrame(data)
colors = [ "#000000" ] * len(data)

sns.scatterplot(x="x", y="y", color=colors, data=df)

The problem, as far as I can tell, is the magic with which seaborn determines colors in line 740 of relational.py. Here, an empty plot is attempted with the kwargs passed, which leads to a mismatch in the length of the c, x and y fields.

I’m not sure what the best solution would be. If the empty plot in line 740 is only needed for the colors, one might want to skip it when colors are specified manually?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mwaskomcommented, Mar 9, 2019

Unfortunately I guess the answer is that this is broken on newer matplotlib versions, and I see no value in trying to convince upstream otherwise; sorry about that.

1reaction
mwaskomcommented, Feb 26, 2019

For some reason the matplotlib developers are constantly changing the c/color functionality. I think this is an irritating example where they’ve made an uneccessary (imo) change and broken seaborn.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Setting different color for each series in scatter plot on matplotlib
The normal way to plot plots with points in different colors in matplotlib is to pass a list of colors as a parameter....
Read more >
scatter plot different colors and markers based on ... - MathWorks
I would like to make a scatter plot showing the different samples with a different colour and the subcategories with a different marker....
Read more >
Solved: Scatter plot colours - Microsoft Power BI Community
I am not able to find how to change data colours on the scatter chart. ... one (let s say black) and then...
Read more >
Visualizing Data in Python Using plt.scatter()
In this tutorial, you'll learn how to create scatter plots in Python, which are a key part of many data visualization applications.
Read more >
Add Multiple Series of Data to X Y Scatter Chart - YouTube
If you're creating a scatter plot it may begin with one series of x,y data. But later on you may want to put...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found