Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

point labels in pandas.DataFrame.plot #86

Open
jondo opened this issue Jun 14, 2018 · 0 comments
Open

point labels in pandas.DataFrame.plot #86

jondo opened this issue Jun 14, 2018 · 0 comments

Comments

@jondo
Copy link

jondo commented Jun 14, 2018

Is there a way to make point labels work with pandas.DataFrame.plot?

I am using WinPython64-3.6.5.0Qt5 which contains mpldatacursor 0.6.2 and pandas 0.22.0.
I have tried the following (with graphics backend set to "Qt5"):

import pandas as pd
from mpldatacursor import datacursor

df = pd.DataFrame([[5.1, 3.5, 0], [4.9, 3.0, 0], [7.0, 3.2, 1],
                   [6.4, 3.2, 1], [5.9, 3.0, 2]],
                  columns=['length', 'width', 'species'])
ax1 = df.plot.scatter(x='length', y='width')

def cursor_format(x, y, event, ind, label, point_label, s, z, c):
    return str(point_label[0])

datacursor(ax1, formatter=cursor_format, point_labels=list(df['species']))

Selecting a point gives me TypeError: cursor_format() missing 3 required positional arguments: 's', 'z', and 'c', and when I remove these three arguments from the function definition, I get TypeError: 'NoneType' object is not subscriptable, because point_label is not defined.

I also tried:

datacursor(ax1, formatter='{point_label}'.format, point_labels=list(df['species']))

This gives me Labels saying "None".

My workaround is to directly use the matplotlib instead:

import matplotlib.pyplot as plt
ax1 = plt.scatter(df['length'], df['width'])

With this, both formatters work fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant