Matplotlib is a very powerful Python module for drawing two-dimensional graphics, it uses the Python language to achieve the ease of use of MATLAB drawing functions, but also has a very strong customizable. It provides a complete set of command APIs similar to those of MATLAB and is ideal for interactive mapping. It can also be easily used as a drawing control, embedded in GUI applications. Its documentation is quite complete, and there are hundreds of thumbnails on the gallery page, and the source program opens. So if you need to draw some kind of diagram, just browse, copy, paste it on this page and basically get it done!
The instance code is as follows:
1. Bar chart
Import Matplotlib.pyplot as Plt Plt.bar (left = 0,height = 1) plt.show ()
The results are 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]) Frac s = [100explode=], #每一块占得比例, sum of 0.08 (0, 0, #离开整体的距离), see effect labels = ' hogs ', ' Dogs ', ' Logs ' #对应每一块的标志pie (fra CS, Explode=explode, labels=labels, autopct= '%1.1f%% ', shadow=true, startangle=90, colors = ("G", "R", "Y")) # StartAngle is the starting angle, the default is 0, starting from here in the counterclockwise direction to expand the title (' Raining Hogs and Dogs ') #标题show ()
The results are as follows: