(1)pyplot基础绘图

 # -*-coding:utf-8-*-
# !/usr/bin/env python
# Author:@vilicute import numpy as np
import matplotlib.pyplot as plt t = np.arange(-5*np.pi, 5*np.pi, 0.01)
plt.title('y=x^2 and y=x^4') # 添加标题
plt.xlabel('x') # x轴名称
plt.ylabel('y') # y轴名称
plt.xlim((-5*np.pi, 5*np.pi)) # x轴范围
plt.ylim((-1, 5)) # y轴范围
plt.xticks([-15, -12, -9, -6, -3, 0, 3, 6, 9, 12, 15]) # x轴刻度
plt.yticks([-1, 0, 1, 2 , 3, 4, 5]) # y轴刻度
plt.plot(t, 4*np.sin(t)/t)
plt.plot(t, t**2)
plt.legend(['y=4*np.sin(t)/t', 'y=x^2']) # 标注说明
plt.show()

(2)多图绘制

 # -*-coding:utf-8-*-
# !/usr/bin/env python
# Author:@vilicute
import numpy as np
import matplotlib.pyplot as plt t = np.arange(0, 2*np.pi, 0.01)
pl = plt.figure(figsize=(8, 6), dpi=80) # 确定画布大小
ax1 = pl.add_subplot(2, 1, 1) # 创建一个2行1列子图,第一个图
plt.title('y=x^2 and y=x^4') # 添加标题
plt.xlabel('x') # x轴名称
plt.ylabel('y') # y轴名称
plt.xlim((0, 1)) # x轴范围
plt.ylim((0, 1)) # y轴范围
plt.xticks([0, 0.2, 0.4, 0.6, 0.8, 1.0]) # x轴刻度
plt.yticks([0, 0.2, 0.4, 0.6, 0.8, 1.0]) # y轴刻度
plt.plot(t, t**2)
plt.plot(t, t**4)
plt.legend(['y=x^2', 'y=x^4']) # 标注说明 ax2 = pl.add_subplot(2, 1, 2) # 第二个图
plt.title('sin(x) and cos(x)')
plt.xlabel('x')
plt.ylabel('y')
plt.xlim((0, np.pi*2))
plt.ylim((-1, 1))
plt.xticks([0, np.pi/2, np.pi, 3*np.pi/2, np.pi*2])
plt.yticks([-1, -0.5, 0, 0.5, 1.0])
plt.plot(t, np.sin(t))
plt.plot(t, np.cos(t))
plt.legend(['sin(x)', 'cos(x)'])
plt.show()

最新文章

  1. ubuntu上安装mysql 编译安装
  2. PHP开发异步高性能的MySQL代理服务器
  3. 应用emailAutoComplete.js来自动显示邮箱后缀列表
  4. web浏览器下的缓存 - Etag
  5. uva 147
  6. exit与return区别
  7. pythonchallenge学到的python内置函数整理
  8. Aix 光盘软件包安装
  9. heap creation
  10. 艰苦的RAW格式数据恢复之旅
  11. Encoding filter 编码过滤器
  12. django.db.utils.ProgrammingError: (1146, "Table 'db_gold.user_ip_info' doesn't exist") RuntimeError: Model class scanhosts.models.HostLoginInfo doesn't declare an explicit app_label and isn't in an a
  13. IOS 极光推送自定义通知遇到的一些坑
  14. 【codelife 阿里技术文章分享——读后感】
  15. vue使用axios请求后端数据
  16. NumPy 中的集合运算
  17. Spring基础之 反射(Reflection)
  18. mybatis oracle 插入自增记录 获取主键值 写回map参数
  19. unity实现3D物体上的事件监听处理
  20. to_char

热门文章

  1. base64,AES,RSA,SHA和MD5等加密方式(jdk)
  2. 深度残差网络——ResNet学习笔记
  3. fwt优化+树形DP HDU 5909
  4. 工控安全入门(五)—— plc逆向初探
  5. spring cloud深入学习(九)-----配置中心服务化和高可用
  6. 2019牛客暑期多校赛(第一场) A Equivalent Prefixes(单调栈)
  7. 44个 Javascript 变态题解析 (下)
  8. java文件配置MySQL
  9. Java爬虫的实现
  10. goland快捷键使用