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


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



1: Set X|Y axis text label 


import numpy as np
import matplotlib.pyplot as plt
from pylab import mpl

'''
  Function: Set the label text of the X|Y axis
  Call function: plt.xlabel(string); plt.ylabel(string)
  Parameter Description:
    string: the text of the label
    
'''

#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, "-.", lw=2, c="c", label="X|Y axis setting label text")

plt.legend()

plt.xlabel("X-axis coordinate axis")

plt.ylabel("Y-axis coordinate axis")

plt.show()

2: Set the X|Y axis text label running effect

Three: Add grid ticks and colors to the graph


import numpy as np
import matplotlib.pyplot as plt
from pylab import mpl

'''
  Line number function: Draw grid lines of tick marks
  Calling function signature: plt.grid(linestyle=":",color="g")
  Parameter Description:
    linestyle: Line style of grid lines
    color: The line color of the grid lines
'''

#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="Grid grid function creates grid background and polyline color")

plt.legend()

plt.xlabel("X-axis coordinate axis")

plt.ylabel("Y-axis coordinate axis")
plt.grid(linestyle=":", color="r")

plt.show()

Four: Add grid ticks and color running effects

Guess you like

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