Example of integration of Python function drawing and advanced algebra (4): Setting the X|Y axis reference line|reference area


Examples of integration of Python function drawing and advanced algebra (1): sine function and cosine function

Examples of integration of Python function drawing and advanced algebra (2): Flashpoint function

Example of integration of Python function drawing and advanced algebra (3): setting X|Y axis|grid lines

Example of integration of Python function drawing and advanced algebra (4): Setting the X|Y axis reference line|reference area

Examples of integration of Python function drawing and advanced algebra (5): Comprehensive case of line graphs

Examples of integration of Python function drawing and advanced algebra (6): bar chart | histogram | pie chart

Examples of integration of Python function drawing and advanced algebra (7): Limit diagram | Scatter bubble diagram

Examples of integration of Python function drawing and advanced algebra (8): box plot | error bar plot | stacked plot

 



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()

Four: Draw the reference area running effect perpendicular to the X|Y axis 

Guess you like

Origin blog.csdn.net/u014635374/article/details/133177055