Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enter manually a key-value to seaborn jointplot stat_func?

Tags:

python

seaborn

i want to display some parameter on a seaborn jointplot.

Lets say apples=5 just like pearson=.3

I am not interested in the default option. so i generated the graph with the following line of code:

sns.jointplot(sp.time, mn, color="#4CB391", stat_func=None)

The Documentation states:

stat_func : callable or None, optional
Function used to calculate a statistic about the relationship and annotate the plot. 
Should map x and y either to a single value or to a (value, p) tuple. 
Set to None if you don’t want to annotate the plot.

could someone help fill in the stat_func properly do display a key-value pair of my choosing?

Thank you.

The plot is enter image description here

like image 212
George Pamfilis Avatar asked Dec 21 '25 17:12

George Pamfilis


1 Answers

You can create you own function that takes two input parameters (x and y from the call to sns.jointplot()) and returns a value or a tuple of two values. If you just want to display arbitrary text, it is better to use ax.text() as indicated in @mwaskom's comment to your question. But if you are calculating something from a function of your own, you could do:

import seaborn as sns
tips = sns.load_dataset('tips')

def apples(x, y):
    # Actual calculations go here
    return 5

sns.jointplot('tip', 'total_bill', data=tips, stat_func=apples)

enter image description here

If apples() returned two values in a tuple (e.g. return (5, 0.3)), the second value would represent p and the resulting text annotation would be apples = 5; p = 0.3.

You could compute any statistics like this, as long as the return format is a single value or a (value, p) tuple. If you want to use scipy.stats.kendalltau for example, you would do

from scipy import stats
sns.jointplot('tip', 'total_bill', data=tips, stat_func=stats.kendalltau)

enter image description here

like image 200
joelostblom Avatar answered Dec 23 '25 07:12

joelostblom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!