2-3 Numpy+Matplotlib可视化(一)
2024-10-08 01:26:29
(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()
最新文章
- ubuntu上安装mysql 编译安装
- PHP开发异步高性能的MySQL代理服务器
- 应用emailAutoComplete.js来自动显示邮箱后缀列表
- web浏览器下的缓存 - Etag
- uva 147
- exit与return区别
- pythonchallenge学到的python内置函数整理
- Aix 光盘软件包安装
- heap creation
- 艰苦的RAW格式数据恢复之旅
- Encoding filter 编码过滤器
- 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
- IOS 极光推送自定义通知遇到的一些坑
- 【codelife 阿里技术文章分享——读后感】
- vue使用axios请求后端数据
- NumPy 中的集合运算
- Spring基础之 反射(Reflection)
- mybatis oracle 插入自增记录 获取主键值 写回map参数
- unity实现3D物体上的事件监听处理
- to_char