Skip to content Skip to sidebar Skip to footer

How To Set The Hue Range For A Numeric Variable Using A Colored Bubble Plot In Seaborn, Python?

I'm trying to use seaborn to create a colored bubbleplot of 3-D points (x,y,z), each coordinate being an integer in range [0,255]. I want the axes to represent x and y, and the hue

Solution 1:

Following @JohanC's suggestion of using hue_norm was the solution. I first tried doing so by removing the [hue=] parameter and only using the [hue_norm=] parameter, which didn't produce any colors at all (which makes sense).

Naturally one should use both the [hue=] and the [hue_norm=] parameters.

import seaborn
seaborn.set()
import pandas
import matplotlib.pyplot

x               = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200]
y               = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 200]
z               = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 255]

df = pandas.DataFrame(list(zip(x, y, z, my_sizes)), columns =['x', 'y', 'z']) 

ax = seaborn.scatterplot(x="x", y="y",
                 hue="z", 
                 hue_norm=(0,255),        # <------- the solution
                 data=df)

matplotlib.pyplot.xlim(0,255)
matplotlib.pyplot.ylim(0,255)
matplotlib.pyplot.show()

Post a Comment for "How To Set The Hue Range For A Numeric Variable Using A Colored Bubble Plot In Seaborn, Python?"