1, matplotlib drawing trilogy
(1) Create a canvas
(2) Drawing - Drawing and comprising a modified pattern
(3) Drawing Display
2, the line graph
(1) Import Module
import matplotlib.pyplot as plt
import numpy as np
The module into a script, and change the name to plt
(2) Create a canvas
plt.figure(figsize=(8,5), dpi=120)
Use figure () to create a canvas method, figsize = (the X-, the y-) parameter is used to set the canvas size in inches, dpi is used to set the parameters of image pixels
matplotlib default does not support Chinese characters and symbols and
plt.rcParams['font.sans-serif'] = 'SimHei' plt.rcParams['axes.unicode_minus'] = False
Added to the above two lines of code, it is possible to display Chinese and symbols
(3) Drawing - including drawings and graphics modification
-
Horizontal and vertical axes data preparation
= X (np.array ([1908.3, 3158.2, 4140.6, 5510.2, 2015.3, 3235.0, 4453.8, 5798.4 , 2147.6, 3385.8, 4731.2, 5925.6, 2222.5, 3447.2, 5046.1, 6254.4 ]), np.array ([ 9548.0, 11127.5 , 11887.0, 13102.3, 10641.7, 12312.9, 12790.3 , 13915.8, 11320.0, 13300.1, 14024.3, 15461.0, 13146.6, 15219.9 ]), np.array ([ 9873.6, 9757.7, 9684.9, 10581.7, 11429.4, 11178.6, 11089.3, 12002.6 , 12827.3, 12508.9, 12501.8, 13583.8, 14456.4, 13870.2, 13946.9 ]) ) Labels = [ " the first industry " , " secondary industry " , "The tertiary industry " ]
- Drawing boxplot
plt.boxplot(x, notch=True, labels=labels, meanline=True, showmeans=True)
Use Boxplot () method to draw box plots, related parameters Notch : if notched, Labels : label box, meanline : average, you must showmean used together to display the average
- Increase in headline
plt.title ( "GDP box plots")
Use title () method to increase the chart title
- Increase the horizontal axis name
plt.xlabel ( "industry", verticalalignment = "top")
Using the xlabel () method sets the name of the horizontal axis, the parameter VerticalAlignment : setting the location name
- Increase the longitudinal axis of the name
plt.ylabel ( "GDP ($ billion)", rotation = 0, horizontalalignment = "right")
Use ylabel () method sets the name of the longitudinal axis, the parameter HorizontalAlignment : the name of the installation position, rotation : rotation angle setting name
- save Picture
plt.savefig ( "./ GDP box plots .png")
Use savefig () method for storing the plotted image is a line chart, picture parameters for the path name +
(4) drawing shows
plt.show()
Using the show () method of presentation graphics draw, do not add any parameters
3, the final results show
4, the characteristics boxplot
5 is the use of statistics data: minimum, first quartile, median, third quartile, the maximum value of the data to a method described in
Application: to demonstrate the dispersion of a set of data, particularly for comparing several samples
Limitations: For large amounts of data, information reflecting the more blurred