Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotations #387

Open
alvarozamora opened this issue Apr 28, 2021 · 2 comments
Open

Annotations #387

alvarozamora opened this issue Apr 28, 2021 · 2 comments
Labels
question Further information is requested

Comments

@alvarozamora
Copy link

How can I add annotations? e.g. plt.annotate(...)

@alvarozamora alvarozamora added the question Further information is requested label Apr 28, 2021
@DanielGoldfarb
Copy link
Collaborator

Alvaro,
Mplfinance does not directly support annotations at this time. However you can gain access to mplfinance's Figure and Axes objects and call the appropriate matplotlib methods to annotate your plot.

I would, however, not recommend calling plt.annotate(...), nor any other plt...() method in general, but rather find the analogous method that can be called directly on a Figure or Axes object (for example Axes.annotate()).

I would also suggest that you read the comments in the links on this post to get additional ideas on how to implement annotations (such as call Axes.text(), etc.

Finally, one thing to keep in mind when using these workarounds: If mpf.plot() kwarg show_nontrading=False (i.e. it's default value), then although you see dates and/or times printed on the x-axis, under the hood the x-axis is actually the row number from your dataframe. Therefore, for those annotation apis (text, etc) that take x,y coordinates, the x-coordinate may need to be in units of the dataframe row that contains the particular date you want to specify. I hope that makes sense. I am currently working on an enhancement to provide a method to do this transformation for you. In the meantime, that's what you have to do when specifying x-axis positions. Alternatively set show_nontrading=True and pass in Matplotlib date objects as the x values.

All the best. --Daniel

@DanielGoldfarb
Copy link
Collaborator

here is another example: #58 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants