August 2017
Beginner to intermediate
334 pages
8h 22m
English
Matplotlib has an axis.annotate function that draws an arrow extending across specified x and y coordinates and adds a text label if a string is input. The target coordinates of the pointed location and text label are assigned by the xy and xytext parameters in tuples, respectively. Here is an example of drawing the basic demand-supply curves we learn in high school economics:
import matplotlib.pyplot as pltimport numpy as np# create 1000 equally spaced points between -10 and 10x = np.linspace(0, 10)# Prepare the datay1 = xy2 = 10-x# Plot the datafig, ax = plt.subplots()plt.plot(x,y1,label='Supply')plt.plot(x,y2,label='Demand')# Annotate the equilibrium point with arrow and textax.annotate("Equilibrium", ...Read now
Unlock full access