0

I am looking for an alternative way of plotting data points on the chart.

Let's say I have the following dataframe:

import matplotlib.pyplot as plt
import pandas as pd
import numpy as np

df = pd.DataFrame({'x':np.random.rand(10), 'y':np.random.rand(10)})

I would like to see on the chart the y values above each the data point.

Here the version of @tozCSS, which works fine.

ax = df.plot(kind='line',x='x',y='y')
df[['x','y','y']].apply(lambda row: ax.text(*row),axis=1)

The code below outputs the index as a value on the chart, is there a way to edit it so the y values are output:

ax = df.plot('x', 'y', kind='line')

for k, v in df.iterrows():
    ax.annotate(k, v)

1 Answer 1

1

This code outputs y values and put them on top of each point.

ax = df.plot('x', 'y', kind='line')

for k, v in df.iterrows():
    ax.annotate('(%s)'%v['y'], xy=v, textcoords='data')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.