brodude
brodude

Reputation: 23

Pandas and matplotlib - plot scatter on line graph

I'm building a trading bot and currently backtesting. I have two pandas DataFrames, one much longer than the other. The longer contains all the dates and all the indexes for x amount of years. The other data frame only contain the dates and indexes of which I bought or sold.

Long_frame = {'date':['2020-01-10', '2020-01-11', '2020-01-12', '2020-01-13', '2020-01-14', '2020-01-15'], 'index': [2, 4, 6, 8, 10, 20]}
Short_frame = {'date':['2020-01-10', '2020-01-11', '2020-01-13', '2020-01-15'], 'index': [2, 4, 8, 20]}

When I try to plot this on the same graph the line or scatter of the short list end up really compact in the beginning of the graph. How should I plot this to get a meaningful graph? The optimal graph would be to only have one line, the long one, and plot points on that line where trades occurred.

Thanks!

Upvotes: 0

Views: 107

Answers (1)

drops
drops

Reputation: 1604

You can use the dates for your x-axis:

Long_frame = {'date':['2020-01-10', '2020-01-11', '2020-01-12', '2020-01-13', '2020-01-14', '2020-01-15'],'index': [2, 4, 6, 8, 10, 20]}
Short_frame = {'date':['2020-01-10', '2020-01-11', '2020-01-13', '2020-01-15'], 'index': [2, 4, 8, 20]}


import matplotlib.pyplot as plt

plt.plot(Long_frame['date'], Long_frame['index'])
plt.plot(Short_frame['date'], Short_frame['index'],'.', markersize=15)

The trade date points are located at the date position and both graphs are 'equally distributed'

Upvotes: 1

Related Questions