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



1: Comprehensive example of line graph 

import matplotlib.pyplot as plt
import numpy as np

from pylab import mpl

'''
 Function: Add directional annotation text of graphic content details
  Call signature: plt.annotate("Maximum value of vertex", xy=(np.pi / 2, 1.0), weight="bold", color="r",
             arrowprops=dict(arrowstyle="->", connectionstyle="arc3", color="r"))
  Parameter Description:
     string: the content text of the graphic annotation
     xy: coordinate position of the annotated graphic content
     xytext: content coordinates of the annotation text
     weight: font weight style of annotation text
     color: font color of comment text
     arrowprops: A dictionary of properties for arrows indicating the annotated content           
'''

#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 sinusoidal graphics|annotate function adds directional annotation text for graphic content details")
# Reference line perpendicular to the X|Y axis
plt.axhline(y=0.0, c="r", ls="--", lw=1)
plt.axvline(x=4.5, c="r", ls="--", lw=1)

# Label text for X|Y axis
plt.xlabel("X-axis coordinate axis")
plt.ylabel("Y-axis coordinate axis")
'''
  Function: Text label legend to mark different graphics
  Call signature: plt.legend(loc="lower left")
  Parameter Description:
     loc: the geographical location of the legend in the picture
     That is, the display position of the label label in the plot() function
'''
plt.legend(loc="lower left")

#The annotate function adds directional annotation text for graphic content details
plt.annotate("Maximum value of vertex", xy=(np.pi / 2, 1.0), weight="bold", color="r",
             arrowprops=dict(arrowstyle="->", connectionstyle="arc3", color="r"))
'''
 Function: Add undirected annotation text of graphic content details
  Call signature: plt.text(3.10, 0.09, "y=sin(x)", weight="bold", color="b")
  Parameter Description:
    x: x coordinate of the annotation text
    y: y coordinate of the annotation text
    string: the content of the comment
    weight: The thickness style of the annotation text content
    color: font color of the annotation text content
'''
#Add non-directional annotation text of graphic content details
plt.text(3.10, 0.09, "y=sin(x)", weight="bold", color="b")
'''
 Function: Add title of graphic content
  Call signature: plt.title("Sine function graph")
  Parameter Description:
     string: title text of graphic content
'''
plt.title("Sine function graph")

plt.show()

2: Comprehensive example operation effect of line graph  

Guess you like

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