Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases now! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Hands-On Financial Trading with Python

You're reading from   Hands-On Financial Trading with Python A practical guide to using Zipline and other Python libraries for backtesting trading strategies

Arrow left icon
Product type Paperback
Published in Apr 2021
Publisher Packt
ISBN-13 9781838982881
Length 360 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Authors (2):
Arrow left icon
Sourav Ghosh Sourav Ghosh
Author Profile Icon Sourav Ghosh
Sourav Ghosh
Jiri Pik Jiri Pik
Author Profile Icon Jiri Pik
Jiri Pik
Arrow right icon
View More author details
Toc

Table of Contents (15) Chapters Close

Preface 1. Section 1: Introduction to Algorithmic Trading FREE CHAPTER
2. Chapter 1: Introduction to Algorithmic Trading 3. Section 2: In-Depth Look at Python Libraries for the Analysis of Financial Datasets
4. Chapter 2: Exploratory Data Analysis in Python 5. Chapter 3: High-Speed Scientific Computing Using NumPy 6. Chapter 4: Data Manipulation and Analysis with pandas 7. Chapter 5: Data Visualization Using Matplotlib 8. Chapter 6: Statistical Estimation, Inference, and Prediction 9. Section 3: Algorithmic Trading in Python
10. Chapter 7: Financial Market Data Access in Python 11. Chapter 8: Introduction to Zipline and PyFolio 12. Chapter 9: Fundamental Algorithmic Trading Strategies 13. Other Books You May Enjoy Appendix A: How to Setup a Python Environment

Enriching data points with annotations

The matplotlib.Axes.text(...) method adds a text box to our plots:

ax.text(1, 10000, 'Generated using numpy and matplotlib')
fig

The output is as follows:

Figure 5.8 – Plot displaying Matplotlib text annotations

Figure 5.8 – Plot displaying Matplotlib text annotations

The matplotlib.Axes.annotate(...) method provides more control over the annotations.

The code block that follows uses the following parameters to control the annotation:

  • The xy= parameter specifies the location of the data point.
  • The xytext= parameter specifies the location of the text box.
  • The arrowprops= parameter accepts a dictionary specifying parameters to control the arrow from the text box to the data point.
  • The facecolor= parameter specifies the color and the shrink= parameter specifies the size of the arrow.
  • The horizontalalignment= and verticalalignment= parameters specify the orientation of the text box relative to the data point.

The code...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at ₹800/month. Cancel anytime