MeatBALL
MeatBALL

Reputation: 65

sns, change dot's color in scatterplot according to its y value

I'm looking at different seaborn scatterplots of different data and I'd like to make the hue absolute and not relative.

Currently I'm setting the hue to just be the y axis, but when I'm looking at two different plots of the same kind of data, in both of them the lowest point in each one will be in a certain color even though in one of them this point is much higher than in the other.

I'd like that no matter what data I'm currently looking on 0<y<10 will be colored red for instance, 10<y<20 yellow, and 20<y<30 green. The colors ofc are just an example, I'd rather have all points in different hues of the same color, for example darker as y goes up.

Upvotes: 0

Views: 3838

Answers (1)

Esad
Esad

Reputation: 61

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

iris = pd.read_csv("iris.txt",sep = ",")
iris.head()

enter image description here

fig = plt.figure()
ax = plt.axes()
size = iris.sepal_en.values
plt.scatter(iris.sepal_boy,iris.sepal_en,s = size*30, marker = "o")

enter image description here

As y increases, the size increases. I multiplied the size by 30 to see the difference. Is this what you wanted to achieve?

And for color you can use :

plt.scatter(iris.sepal_boy,iris.sepal_en,s = size*30, c = size,cmap = "viridis", marker = "o")

result: enter image description here

Hope, it helps.

Upvotes: 1

Related Questions