Examples of integration of Python function drawing and advanced algebra (2): Flashpoint function
1: Limit graph drawing
# -*- coding: utf-8 -*- import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np ''' Function function: draw a limit graph on the coordinate axis Call signature: plt.polar(theta) Parameter Description: theta: the angle between the ray of each mark and the limit r: distance from each mark to the origin ''' #Set Chinese display font mpl.rcParams["font.sans-serif"] = ["SimHei"] #Set normal display symbols mpl.rcParams["axes.unicode_minus"] = False # Number of five-pointed stars barSlices = 26 theta = np.linspace(0.0, 2 * np.pi, barSlices, endpoint=False) r = 30 * np.random.rand(barSlices) plt.polar(theta, r, color="chartreuse", linewidth=1, marker="*", mfc="b", ms=20) # ms=20 The size of the five-pointed star plt.title("Example of Limit Graph Drawing") plt.show()
2: Limit graph drawing operation effect
Three: Bubble chart drawing
# -*- coding: utf-8 -*- import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np ''' Function: Two-dimensional data displays three-dimensional data with the help of bubble size Call signature: plt.scatter(x, y) Parameter Description: x: data on x axis y: data on the y axis s: size of scatter markers c: color of scatter mark cmap: a color mapping table that maps floating point numbers to colors ''' #Set Chinese display font mpl.rcParams["font.sans-serif"] = ["SimHei"] #Set normal display symbols mpl.rcParams["axes.unicode_minus"] = False # Random seed density a = np.random.randn(200) # Random seed density b = np.random.randn(200) plt.scatter(a, b, s=np.power(10 * a + 20 * b, 2), c=np.random.rand(200), cmap='twilight_shifted', # twilight_shifted marker="o") # marker="o" bubble shape ''' cmap supports the following values, different values have different effects 'Accent', 'Accent_r', 'Blues', 'Blues_r', 'BrBG', 'BrBG_r', 'BuGn', 'BuGn_r', 'BuPu', 'BuPu_r', 'CMRmap', 'CMRmap_r', 'Dark2', 'Dark2_r', 'GnBu', 'GnBu_r', 'Greens', 'Greens_r', 'Greys', 'Greys_r', 'OrRd', 'OrRd_r', 'Oranges', 'Oranges_r', 'PRGn', 'PRGn_r', 'Paired', 'Paired_r', 'Pastel1', 'Pastel1_r', 'Pastel2', 'Pastel2_r', 'PiYG', 'PiYG_r', 'PuBu', 'PuBuGn', 'PuBuGn_r', 'PuBu_r', 'PuOr', 'PuOr_r', 'PuRd', 'PuRd_r', 'Purples', 'Purples_r', 'RdBu', 'RdBu_r', . 'RdGy', 'RdGy_r', 'RdPu', 'RdPu_r', 'RdYlBu', 'RdYlBu_r', 'RdYlGn', 'RdYlGn_r', 'Reds', 'Reds_r', 'Set1', 'Set1_r', 'Set2', 'Set2_r', 'Set3', 'Set3_r', 'Spectral', 'Spectral_r', 'Wistia', 'Wistia_r', 'YlGn', 'YlGnBu', 'YlGnBu_r', 'YlGn_r', 'YlOrBr', 'YlOrBr_r', 'YlOrRd', 'YlOrRd_r', 'afmhot', 'afmhot_r', 'autumn', 'autumn_r', 'binary', 'binary_r', 'bone', 'bone_r', 'brg', 'brg_r', 'bwr', 'bwr_r', 'cividis', 'cividis_r', 'cool', 'cool_r', 'coolwarm', 'coolwarm_r', 'copper', 'copper_r', 'cubehelix', 'cubehelix_r', 'flag', 'flag_r', 'gist_earth', 'gist_earth_r', 'gist_gray', 'gist_gray_r', 'gist_heat', 'gist_heat_r', 'gist_ncar', 'gist_ncar_r', 'gist_rainbow', 'gist_rainbow_r', 'gist_stern', 'gist_stern_r', 'gist_yarg', 'gist_yarg_r', 'gnuplot', 'gnuplot2', 'gnuplot2_r', 'gnuplot_r', 'gray', 'gray_r', 'hot', 'hot_r', 'hsv', 'hsv_r', 'inferno', 'inferno_r', 'jet', 'jet_r', 'magma', 'magma_r', 'nipy_spectral', 'nipy_spectral_r', 'ocean', 'ocean_r', 'pink', 'pink_r', 'plasma', 'plasma_r', 'prism', 'prism_r', 'rainbow', 'rainbow_r', 'seismic', 'seismic_r', 'spring', 'spring_r', 'summer', 'summer_r', 'tab10', 'tab10_r', 'tab20', 'tab20_r', 'tab20b', 'tab20b_r', 'tab20c', 'tab20c_r', 'terrain', 'terrain_r', 'turbo', 'turbo_r', 'twilight', 'twilight_r', 'twilight_shifted', 'twilight_shifted_r', 'viridis', 'viridis_r', 'winter', 'winter_r' ''' plt.title("Scatter Random Bubble Chart Example") plt.show()
Four: Bubble chart drawing operation effect
Five: Cotton swab drawing
# -*- coding: utf-8 -*- import matplotlib as mpl import matplotlib.pyplot as plt import numpy as np ''' Function: Draw discrete ordered data Call signature: plt.stem(x, y) Parameter Description: x: Specifies the position of the cotton swab on the x-axis baseline y: Draw the length of the cotton swab linefmt: cotton swab style markerfmt: The style of the end of the cotton swab basefmt: specifies the style of the baseline ''' #Set Chinese display font mpl.rcParams["font.sans-serif"] = ["SimHei"] #Set normal display symbols mpl.rcParams["axes.unicode_minus"] = False x = np.linspace(0.5, 2 * np.pi, 20) y = np.random.randn(20) plt.stem(x, y, linefmt="-.", markerfmt="o", basefmt="-") plt.title("Drawing a cotton swab diagram") plt.xlabel("X-axis coordinate axis") plt.ylabel("Y-axis coordinate axis") plt.show()