Suppose I have the following chart:
Said graph was created using the following Python code:
from binance.client import Client
import pandas as pd
import matplotlib.pyplot as plt
#personal API key and Secret Key from your Binance account
api_key = "your binance api key"
secret_key = "your binance secret key"
client = Client(api_key= api_key, api_secret= secret_key, tld= "com")
klines_btcusdt = client.get_historical_klines(symbol="BTCUSDT", interval="1h", start_str = "1648807200000", end_str="1653667199999")
df_btcusdt = pd.DataFrame(klines_btcusdt)
#drop unnecesary columns
df_btcusdt.drop(5, inplace = True, axis=1)
df_btcusdt.drop(7, inplace = True, axis=1)
df_btcusdt.drop(8, inplace = True, axis=1)
df_btcusdt.drop(9, inplace = True, axis=1)
df_btcusdt.drop(10, inplace = True, axis=1)
df_btcusdt.drop(11, inplace = True, axis=1)
# Rename the column names for best practices
df_btcusdt.rename(columns = { 0 : 'Start Date',
1 : 'Open Price',
2 : 'High Price',
3 : 'Low Price',
4 :'Close Price',
6 :'End Date',
}, inplace = True)
# Convert Unix Time values to actual dates
df_btcusdt['Start Date'] = pd.to_datetime(df_btcusdt['Start Date'], unit='ms')
df_btcusdt['End Date'] = pd.to_datetime(df_btcusdt['End Date'], unit='ms')
df_btcusdt = df_btcusdt[['End Date','Close Price']]
df_btcusdt = df_btcusdt.set_index('End Date', inplace=False)
df_btcusdt = df_btcusdt.astype({'Close Price': 'float'})
#visualising the price
plt.figure(figsize=(8, 6), dpi=80)
plt.title('BTCUSDT Price')
plt.rc('xtick', labelsize = 8)
plt.plot(df_btcusdt.index[0:], df_btcusdt[0:])
And I am interested in marking 2 specific data points that are: df_btcusdt[0:1]
and df_btcusdt[1024:1025]
, that is:
Close Price
End Date
2022-04-01 05:59:59.999 44646.16
Close Price
End Date
2022-05-13 21:59:59.999 30046.65
But I don't know how to do it, I tried changing the last line of my code to the following:
plt.plot(df_btcusdt.index[0:], df_btcusdt[0:], markevery = [44646.16, 30046.65], marker="ro")
but I get:
ValueError: markevery=[44646.16, 30046.65] is iterable but not a valid numpy fancy index
It should return something like this:
Can I get help please?
Good day,
You only have to obtain a list with the values of "X" and "Y" that you want to mark and graph them with
matplotlib.pyplot.plot
.The styles available by default can be reviewed in
matplotlib.markers.MarkerStyle
.Generic example (For security reasons you avoided putting your keys and I can't generate the same data you have, so I did something generic):
This produces: