Matplotlib is a powerful Python module for drawing two-dimensional graphics. It uses the Python language to implement the ease-of-use of the MATLAB drawing function, and has very powerful customization. It provides a complete set of command APIs similar to matlab and is suitable for interactive plotting. It can also be easily used as a drawing control and embedded into GUI applications. Its documentation is quite complete, and there are hundreds of thumbnails on the Gallery page. After opening it, all the source programs are available. Therefore, if you want to draw a certain type of graph, you can simply browse, copy, and paste it on this page!
The instance code is as follows:
1. Bar Chart
Import matplotlib. pyplot as plt. bar (left = 0, height = 1) plt. show ()
The running effect is as follows:
2. Pie Chart
#! Coding: cp936from pylab import * # make a square figure and axesfigure (1, figsize = (6, 6) ax = axes ([0.1, 0.1, 0.8, 0.8]) fracs = [45, 30, 25] # Percentage of each piece, total: 100 explode = (0, 0, 0.08) # Leave the overall distance, labels = 'hogs', 'dogs', and 'logs' # indicates the pie (fracs, explode = explode, labels = labels, autopct = '% 1.1f %', shadow = True, startangle = 90, colors = ("g", "r", "y") # startangle is the starting angle, the default value is 0. Start from here to expand title ('raining Hogs and Dogs ') # title show ()
The running effect is as follows: