Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Matplotlib for Python Developers. - Second Edition

You're reading from  Matplotlib for Python Developers. - Second Edition

Product type Book
Published in Apr 2018
Publisher Packt
ISBN-13 9781788625173
Pages 300 pages
Edition 2nd Edition
Languages
Authors (3):
Aldrin Yim Aldrin Yim
Profile icon Aldrin Yim
Claire Chung Claire Chung
Profile icon Claire Chung
Allen Yu Allen Yu
Profile icon Allen Yu
View More author details

Table of Contents (16) Chapters

Title Page
Dedication
Packt Upsell
Contributors
Preface
Introduction to Matplotlib Getting Started with Matplotlib Decorating Graphs with Plot Styles and Types Advanced Matplotlib Embedding Matplotlib in GTK+3 Embedding Matplotlib in Qt 5 Embedding Matplotlib in wxWidgets Using wxPython Integrating Matplotlib with Web Applications Matplotlib in the Real World Integrating Data Visualization into the Workflow Index

Text and annotations


To enhance the understanding of plot details, we may sometimes add in text annotations for explanation. We will now introduce the methods of adding and adjusting text in Matplotlib plots.

Adding text annotations

We can add text to our plot by calling plt.text(x,y,text); we specify the x and y coordinates and the text string. Here is a quick example:

plt.text(0.25,0.5,'Hello World!',fontsize=30)
plt.show()

You can see in this figure the Hello World! message appearing in the center of the plot:

Font

Here are some of the common font properties adjustable in Matplotlib:

  • Font size: Float or relative size, for example, smaller and x-large
  • Font weight: For example, bold or semibold
  • Font style: For example, italic
  • Font family: For example, Arial
  • Rotation: Angle in degrees; it is vertical or horizontal

Note

Matplotlib now supports unicode and emoji.

Mathematical notations

As a plotting tool, mathematical notations are common. We can use the in-built mathtext or LaTeX to render mathematical...

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 $15.99/month. Cancel anytime}