Is there a way to set the hue class in a seaborn regression plot?

278 Views Asked by At

I have a dataset composed of four columns, as follows:

Ice Core nssSO4 Cl Na
IC-02 31.71 413.68 32.75

And so on...

There are 5 different Ice Core categories and I made graphics correlating the Na with the Cl using the lmplot from the seaborn library. For this graphics, I used the col parameter to divide the Ice Core categories in different facets. What I want to do is to set the hue parameter as the nssSO4 so I can visualize it as a color gradient in the Na x Cl scatterplot. This is what I did.

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

missing_values = ['no data', 'na', 'no sample', 'nd', 'n.a.', 'n.d.']
df = pd.read_csv('data.csv', na_values=missing_values)
sns.set_style('white')

Na_Cl = sns.lmplot(x='Na', y='Cl', data=df, hue='nssSO4', scatter_kws= 
{'edgecolor':'black', 'alpha': 0.6}, line_kws={'lw': 1}, col='Ice Core', fit_reg=True)

Na_Cl.set_titles(col_template='{col_name}')
plt.show()

Since my nssSO4 data is floattype, I thought it would automatically create classes to classify the data in the scatterplot, but it seems it's created a class for every value, so there are thousands of classes. The result is not what I intended. I wanted like 5 to 10 classes of nssSO4 so I could see a colour gradient in my Na x Cl scatterplot.

Also, is there a function which I can call to get the 'n' number of data points in each scatterplot column?

Thanks in advance.

0

There are 0 best solutions below