博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python:使用matplotlib绘制图表
阅读量:7070 次
发布时间:2019-06-28

本文共 1057 字,大约阅读时间需要 3 分钟。

   今天看了一下使用python绘制图表的方法,有个强大的类库matplotlib,可以制作出高质量的2D和3D图形,先记录一下,以后慢慢学习。

   matplotlib下载及API手册地址:

   数学库numpy下载及API手册地址:

   几个绘图的例子,来自API手册:

1、最简单的图:

代码:

#!/usr/bin/env python import matplotlib.pyplot as plt plt.plot([10, 20, 30]) plt.xlabel('tiems') plt.ylabel('numbers') plt.show()

测试:

2.饼图:

代码:

#!/usr/bin/env python # -*- coding: utf-8 -*- from pylab import * # make a square figure and axes figure(1, figsize=(6,6)) ax = axes([0.1, 0.1, 0.8, 0.8]) labels = 'Frogs', 'Hogs', 'Dogs', 'Logs' fracs = [15,30,45, 10] explode=(0, 0.05, 0, 0) pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%', shadow=True) title('Raining Hogs and Dogs', bbox={'facecolor':'0.8', 'pad':5}) savefig('D:\\pie.png') show()

测试:

 

3、使用numpy库函数:

代码:

#!/usr/bin/env python # -*- coding: utf-8 -*- import numpy as np import matplotlib.pyplot as plt t = np.arange(0.0, 1.01, 0.01) s = np.sin(2*2*np.pi*t) plt.fill(t, s*np.exp(-5*t), 'r') plt.grid(True) #保存为PDF格式,也可保存为PNG等图形格式 plt.savefig('D:\\test.pdf') plt.show()

测试:

 

  

转载于:https://www.cnblogs.com/dyx1024/archive/2012/02/27/2556700.html

你可能感兴趣的文章
11.14/11.15 Apache和PHP结合 11.16/11.17 Apache默认虚拟主机
查看>>
TeeChart Pro VCL/FMX教程(六):使用系列(一)
查看>>
Dubbo分析之Cluster层
查看>>
Titan Framework MongoDB深入理解3
查看>>
iOS核心动画笔记2-寄宿图
查看>>
几种不同类型网站内容优化切入点
查看>>
SaltSack入门(三)Salt相关命令和Pillar应用
查看>>
文件上传相关内容
查看>>
Linux下Nodejs安装(完整详细)
查看>>
OSChina 周四乱弹 —— 想换行了怎么办,别说按回车键
查看>>
ubuntu11.04安装JDK7及配置环境
查看>>
SpringBoot+Logback+Sentry(日志监控平台)
查看>>
vmware10中开启Intel VT-x
查看>>
一般wsdl生成的类都比较大,IDEA类文件大小限制导致无法加载该类问题
查看>>
Android 垂直Tab
查看>>
Android DecorView与ViewRootImpl
查看>>
goroutine 相关知识7
查看>>
redis命令学习笔记
查看>>
原生JS实现"旋转木马"效果的图片轮播插件
查看>>
RabbitMQ镜像队列
查看>>