1

I am trying to plot BUY, SELL, BCLOSE and SCLOSE points only (i.e not SIT or SHRTCLS etc) from dataframe column C on the matplotlib chart that can be generated below

Eg. the at the 2nd price point in column B (5.53) as it is a BUY I am trying to plot this point on the line of the graph. The 4th price in col B is BCLOSE and this should also be added to the graph and so on.

thanks for your time.

import pandas as pd
import matplotlib.pyplot as plt

 df = pd.DataFrame()
df['A'] = ('11/06/2019','10/06/2019','9/06/2019','8/06/2019','7/06/2019','6/06/2019','5/06/2019','4/06/2019','3/06/2019','2/06/2019','1/06/2019','31/05/2019','30/05/2019')
df['B'] = (5.97,5.53,5.13,4.85,4.87,4.92,4.9,5.66,5.66,5.72,5.72,5.68,6.05)
df['C'] = ('BHODL','BUY','SIT','BCLOSE','BUY','SIT','SELL','SIT','SIT','SIT','SHRTCLS','BCLSHRT','SELL')
print(df)

ax = df.plot(title='tesing123')
ax.set_xlabel('date')
ax.set_ylabel('price')
ax.grid()
plt.show()

2 Answers 2

1

Use -

ax = df[df['C'].isin(['BUY','SELL','BCLOSE','SCLOSE'])].plot(title='tesing123')
ax.set_xlabel('date')
ax.set_ylabel('price')
ax.grid()
plt.show()

Output

enter image description here

Sign up to request clarification or add additional context in comments.

2 Comments

Firstly thank you for your reply. I however must not have explained myself properly. I would like price and date to be plotted as per the dataframe, I simply however want the words BUY, SELL, BCLOSE and SCLOSE to be actually written on the point on the line on the graph when they occur
2/ like a scatter plot on top of the line graph
0

Try using this code:

z = df['A']
y = df['B']
n = df['C']

ax = df.plot(title='tesing123')

ax.scatter(z, y)

for i, txt in enumerate(n):
    ax.annotate(txt, (z[i], y[i]))

ax.grid()

plt.show()

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.