Examples of integration of Python function drawing and advanced algebra (2): Flashpoint function
1: Draw a reference line parallel to the X|Y axis
import matplotlib.pyplot as plt
import numpy as np
from pylab import mpl
'''
Function: Draw a reference line parallel to the X|Y axis
Call signature: plt.axhline(y=0.0,c="r",ls="--",lw=2) | plt.axvline(x=4.0, c="r", ls="--", lw=2)
Parameter Description:
y: starting point of the horizontal reference line
c: Reference line line color
ls: line style of the reference line
lw: Reference small line width
'''
#Set Chinese display font
mpl.rcParams["font.sans-serif"] = ["SimHei"]
#Set normal display symbols
mpl.rcParams["axes.unicode_minus"] = False
x = np.linspace(0.05, 10, 1000)
y = np.sin(x)
plt.plot(x, y, ls="-.", lw=2, c="c", label="plot function draws the sine function, axhline|axvline sets the horizontal and vertical reference lines")
plt.legend()
plt.axhline(y=0.0, c="r", ls="--", lw=1)
plt.axvline(x=4.5, c="r", ls="--", lw=1)
plt.show()
2: The effect of drawing a reference line parallel to the X|Y axis
Three: Draw a reference area perpendicular to the X|Y axis
import matplotlib.pyplot as plt
import numpy as np
from pylab import mpl
'''
Function: Draw a reference area perpendicular to the X|Y axis
Call signature:
plt.axvspan(xmin=4.0, xmax=6.0, facecolor="y", alpha=0.3)
plt.axhspan(ymin=0.0, ymax=0.5, facecolor="y", alpha=0.3)
Parameter Description:
xmin: starting position of the reference area
xmax: the end position of the reference area
facecolor: fill color of reference area
alpha: Reference area color fill transparency
'''
#Set Chinese display font
mpl.rcParams["font.sans-serif"] = ["SimHei"]
#Set normal display symbols
mpl.rcParams["axes.unicode_minus"] = False
x = np.linspace(0.05, 10, 1000)
y = np.sin(x)
plt.plot(x, y, ls="-.", lw=2, c="c", label="plot function draws a sinusoidal image|axvspace function draws an area perpendicular to the X|Y axis")
plt.legend()
plt.axvspan(xmin=4.0, xmax=6.0, facecolor="y", alpha=0.3)
plt.axhspan(ymin=0.0, ymax=0.5, facecolor="y", alpha=0.3)
plt.show()