Adding text to both axis and figure objects

Let's start by importing everything we need:

import numpy as npimport matplotlib as mplimport matplotlib.pyplot as plt%matplotlib inline# Set up figure size and DPI for screen demoplt.rcParams['figure.figsize'] = (6,4)plt.rcParams['figure.dpi'] = 150
  1. Next, bring up the standard sine curve that we have been using:
# Add some textnums = np.arange(0,10,0.1)plt.plot(nums, np.sin(nums))

We will get the following output:

  1. We will add some text, say, right in the middle of the two curves. We will use the text method, and since we are taking the data coordinates, the middle of this plot would be (5, ...

Get Mastering Matplotlib 2.x now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.