Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Seaborn graphing: Highlighting single data point in jointplot

Tags:

I'm trying to just highlight a single point on a Seaborn jointplot, but I'm coming up a little short. I'm able to plot the point from matplotlib - it's just not showing up in the same chart. What am I doing wrong? Thanks!

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

#make some sample data
test_x = [i for i in range(10)]
test_y = [j for j in range(10)]

df = pd.DataFrame({'xs':test_x,
                  'ys':test_y})

#make Seaborn chart
g = sns.jointplot(x="xs", y="ys", data = df)


#sort the table to find the top y value
df = df.sort_values('ys', ascending = False)

#find coordinates of this point
highlight_x = df.iloc[0,0]
highlight_y = df.iloc[0,1]

#this is wrong - I want it to be in the same chart
plt.scatter(highlight_x, highlight_y, color = 'red')

plt.show()

Output from this code

like image 645
user6142489 Avatar asked Oct 17 '17 13:10

user6142489


1 Answers

plt.scatter will plot in the current axes. The current axes is (apparently) the one on the right, not the central one. It would hence be better to directly specify the axes to which to plot. The central axes of a JointGrid g can be obtained via g.ax_joint:

g = sns.jointplot(...)
# ...
g.ax_joint.scatter(highlight_x, highlight_y, color = 'red')
like image 133
ImportanceOfBeingErnest Avatar answered Sep 30 '22 01:09

ImportanceOfBeingErnest