Home > Backend Development > Python Tutorial > python的绘图工具matplotlib使用实例

python的绘图工具matplotlib使用实例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-16 08:43:29
Original
1570 people have browsed it

matplotlib是功能十分强大的绘制二维图形的Python模块,它用Python语言实现了MATLAB画图函数的易用性,同时又有非常强大的可定制性。它提供了一整套和matlab相似的命令API,十分适合交互式地进行制图。而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中。它的文档相当完备,并且Gallery页面中有上百幅缩略图,打开之后都有源程序。因此如果你需要绘制某种类型的图,只需要在这个页面中浏览、复制、粘贴一下,基本上都能搞定!

实例代码如下:

1. 柱状图

import matplotlib.pyplot as plt 
plt.bar(left = 0,height = 1)
plt.show()

Copy after login

运行效果如下:

2. 饼形图

#! coding: cp936
from pylab import *
# make a square figure and axes
figure(1, figsize=(6,6))
ax = axes([0.1, 0.1, 0.8, 0.8])
fracs = [45, 30, 25]       #每一块占得比例,总和为100
explode=(0, 0, 0.08)       #离开整体的距离,看效果
labels = 'Hogs', 'Dogs', 'Logs' #对应每一块的标志
pie(fracs, explode=explode, labels=labels,
        autopct='%1.1f%%', shadow=True, startangle=90, colors = ("g", "r", "y"))
                 # startangle是开始的角度,默认为0,从这里开始按逆时针方向依次展开
title('Raining Hogs and Dogs')  #标题
show()
Copy after login

运行效果如下:

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template