2

I'm trying to plot a time series data so that I can display buy and sell points on the data itself.

This is how the data looks like:

Dataframe

This is the close price line chart:

Close price line chart

This is the buy sell signals (I'm only printing buy sell signals for now but I'm going to store them into a new dataframe):

Buy_Sell Prints

I'm not trying to label every data point but the points in my buy-sell list. I need to match the dates in both dataframes and add a green up-arrow for buys, red down-arrow for sells. An example solution:

Buy-sell signals on historical data

How can I do this?

iso_9001_
  • 2,655
  • 6
  • 31
  • 47
  • With ax.annotate. https://matplotlib.org/users/annotations.html What happens when you try that? – Heath Raftery Jun 14 '19 at 14:12
  • I'm very new to matplotlib. I researched and tried `markevery` option but did not yield what I wanted. Can you give me a working example? – iso_9001_ Jun 14 '19 at 14:17
  • Lots of generic examples on the linked page. For something more specific, add some of your code to your question. – Heath Raftery Jun 14 '19 at 14:23

1 Answers1

0

It looks like you're using pyplot from matplotlib. If that's the case there's already a solution for that here: Label python data points on plot

If you want something with a bit more detail Matplotlib has a page on this themselves as well. They show you how to use the arrows that you have in this example: https://matplotlib.org/3.1.0/gallery/text_labels_and_annotations/annotation_demo.html

Walklikeapenguin
  • 127
  • 2
  • 10
  • I'm not trying to label `every` data point but the points in my `buy-sell list`. I need to match the date and add a green up-arrow for buys, red down-arrow for sells – iso_9001_ Jun 14 '19 at 14:21
  • You could add another series to the same plot with only the points you're interested in labeling. – aganders3 Jun 14 '19 at 14:27
  • That's exactly what the Matplotlib tutorial shows- you specify each point that you want to be labled like this: ``ax.annotate('axes fraction', xy=(3, 1), xycoords='data', xytext=(0.8, 0.95), textcoords='axes fraction', arrowprops=dict(facecolor='black', shrink=0.05), horizontalalignment='right', verticalalignment='top') `` where xy=(3,1) specifies the point at (3,1). You could iterate through your buy-sell list and populate that xy field with each value you have. Then just use an offset to get the label where you want it. – Walklikeapenguin Jun 14 '19 at 15:01