7

Is it possible to create some kind of hover tooltip from pandas dataframe on a linear regression plot from seaborn library?

More specifically I have this code:

import pandas as pd
import numpy as np
from pandas import Series, DataFrame
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
dframe=pd.read_csv('pokemon.csv')
sns.lmplot('hp', 'total', dframe)

And the result is the linear regression chart. How can I create such a tooltip, that when i hover over one of the dots on the chart, the corresponding value from one of the columns in that dframe will be displayed? In this case the name of the Pokemon.

The csv file comes from Kaggle.

cchamberlain
  • 17,444
  • 7
  • 59
  • 72
Alex T
  • 3,529
  • 12
  • 56
  • 105
  • 1
    related: http://stackoverflow.com/questions/31480921/how-to-make-mpld3-work-with-seaborn-interactive-tooltips – EdChum Dec 20 '16 at 21:27
  • This is probably trivially easy with bokeh. Check out the tooltips in bokeh here: http://bokeh.pydata.org/en/latest/docs/user_guide/tools.html#basic-tooltips – Ted Petrou Dec 20 '16 at 21:35
  • Hmm So can bookeh be linked to the seaborn chart? Or shall I create a the same chart using bookeh? Im not sure if bookeh has linear regression plotting. – Alex T Dec 20 '16 at 21:43
  • `bokeh` doesn't implement linear regression directly, no, but you can build it yourself using e.g. `statsmodels`. If you absolutely need interaction of this sort, `bokeh` is the way to go. It's technically possible to do in `matplotlib`, as some answers here have demonstrated in the past, but it's very painful and absolutely not something you want to attempt. – Aleksey Bilogur Dec 24 '16 at 06:50
  • I actually dont need the linear regression that much but the scatter plot is more what I'm trying to do, will update when done(is bookeh good for that too?) – Alex T Dec 26 '16 at 12:40
  • This is a very old post but I found another response on Stack Overflow that answers this question - https://stackoverflow.com/questions/7908636/possible-to-make-labels-appear-when-hovering-over-a-point-in-matplotlib – Joe Ferndz Dec 30 '20 at 06:06
  • That would be good starting point for me to check if Seaborn has also this feature. I remember that I found something for matplotlib, but tooltips with seaborn did not work in similar way. – Alex T Dec 30 '20 at 08:16

0 Answers0