Pthon Matplotlib 画图
一、普通绘图
import matplotlib.pyplot as plt
import numpy as np # 绘制普通图像
x = np.linspace(-1, 1, 50)
y1 = 2 * x + 1
y2 = x**2 plt.figure()
# 在绘制时设置lable, 逗号是必须的
l1, = plt.plot(x, y1, label = 'line')
l2, = plt.plot(x, y2, label = 'parabola', color = 'red', linewidth = 1.0, linestyle = '--') # 设置坐标轴的取值范围
plt.xlim((-1, 1))
plt.ylim((0, 2)) # 设置坐标轴的lable
plt.xlabel('X axis')
plt.ylabel('Y axis') # 设置x坐标轴刻度, 原来为0.25, 修改后为0.5
plt.xticks(np.linspace(-1, 1, 5))
# 设置y坐标轴刻度及标签, $$是设置字体
plt.yticks([0, 0.5], ['$minimum$', 'normal']) # 设置legend
plt.legend(handles = [l1, l2,], labels = ['a', 'b'], loc = 'best')
plt.show()
二、自定义单峰函数
import math
import numpy as np
import matplotlib.pyplot as plt x = np.linspace(-30, 30, 500)
y = []
y2 = []
a = 3
b = 0
c = 25
for i in x :
# 类似高斯函数,a 代表峰值, b对称轴位置,c方差
temp = a * math.exp(-(i-b)**2 / (2 * c))
y.append(temp)
#对上一个单峰函数值进行放大处理,红色虚线部分
y2.append(math.exp(temp)) plt.figure()
l1= plt.plot(x, y, label = 'line')
l2, = plt.plot(x, y2, label = 'parabola', color = 'red', linewidth = 1.0, linestyle = '--')
plt.show()
三、画subplot子图(2 x 2 为例)
import matplotlib.pyplot as plt
t=np.arange(0.0,2.0,0.1)
s=np.sin(t*np.pi)
plt.subplot(2,2,1) #要生成两行两列,这是第一个图plt.subplot('行','列','编号')
plt.plot(t,s,'b--')
plt.ylabel('y1')
plt.subplot(2,2,2) #两行两列,这是第二个图
plt.plot(2*t,s,'r--')
plt.ylabel('y2')
plt.subplot(2,2,3)#两行两列,这是第三个图
plt.plot(3*t,s,'m--')
plt.subplot(2,2,4)#两行两列,这是第四个图
plt.plot(4*t,s,'k--')
plt.show()
点图和线图
fig = plt.figure()
ax = fig.add_subplot(221, projection='3d')
ax.plot(array_normal[:,0],array_normal[:,1],array_normal[:,2])
plt.subplot(2,2,2)
plt.plot(np.arange(0,sample_len,1), signal_normal) normal_pow = array_normal[:,2] ax3 = fig.add_subplot(223, projection='3d')
ax3.plot(array_anomaly[:,0],array_anomaly[:,1],array_anomaly[:,2]) anomaly_pow = array_anomaly[:,2]
plt.subplot(2,2,4)
plt.scatter(np.arange(0,sample_len,1), signal_anomaly)
plt.show()
【Reference】
[1] https://www.jianshu.com/p/de223a79217a
[2] https://www.cnblogs.com/xingshansi/p/6777945.html
Pthon Matplotlib 画图的更多相关文章
- python matplotlib画图产生的Type 3 fonts字体没有嵌入问题
ScholarOne's 对python matplotlib画图产生的Type 3 fonts字体不兼容,更改措施: 在程序中添加如下语句 import matplotlib matplotlib. ...
- 使用python中的matplotlib 画图,show后关闭窗口,继续运行命令
使用python中的matplotlib 画图,show后关闭窗口,继续运行命令 在用python中的matplotlib 画图时,show()函数总是要放在最后,且它阻止命令继续往下运行,直到1.0 ...
- matplotlib 画图
matplotlib 画图 1. 画曲线图 Tompson = np.array([0, 0, 0, 0, 0.011, 0.051, 0.15, 0.251, 0.35, 0.44, 0 ...
- matplotlib画图
matplotlib画图 import numpy as np import matplotlib.pyplot as plt x1=[20,33,51,79,101,121,132,145,162, ...
- python3 使用matplotlib画图出现中文乱码的情况
python3使用matplotlib画图,因python3默认使用中unicode编码,所以在写代码时不再需要写 plt.xlabel(u’人数’),而是直接写plt.xlabel(‘人数’). 注 ...
- matplotlib画图实例:pyplot、pylab模块及作图參数
http://blog.csdn.net/pipisorry/article/details/40005163 Matplotlib.pyplot画图实例 {使用pyplot模块} matplotli ...
- python使用matplotlib画图
python使用matplotlib画图 matplotlib库是python最著名的画图库.它提供了一整套和matlab类似的命令API.十分适合交互式地进行制图. 先介绍了怎样使用matplotl ...
- matplotlib画图报错This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
之前用以下代码将实验结果用matplotlib show出来 plt.plot(np.arange(len(aver_reward_list)), aver_reward_list) plt.ylab ...
- matplotlib画图出现乱码情况
python3使用matplotlib画图,因python3默认使用中unicode编码,所以在写代码时不再需要写 plt.xlabel(u’人数’),而是直接写plt.xlabel(‘人数’). 注 ...
随机推荐
- verilog语法实例学习(11)
同步时序电路的一般形式 时序电路由组合逻辑以及一个或多个触发器实现.一般的架构如下图所示:W为输入,Z为输出,触发器中存储的状态为Q.在时钟信号的控制下,触发器通过加在其输入端的组合逻辑输入,使得电路 ...
- C++11 多线程编程 使用lambda创建std::thread (生产/消费者模式)
要写个tcp server / client的博客,想着先写个c++11多线程程序.方便后面写博客使用. 目前c++11中写多线程已经很方便了,不用再像之前的pthread_create,c++11中 ...
- 【PMP】项目和运营的区别
运营管理关注产品的持续性生产和服务的持续运作. 项目与运营会存在产品生命周期的不同时点交叉,例如: 在产品开发.产品升级或提高产量时: 在改进运营或产品开发流程时: 在产品生命周期结束阶段: 在每个收 ...
- 开发指南专题五:JEECG微云高速开发平台代码生成器
开发指南专题五:JEECG微云高速开发平台代码生成器 1.1. Maven开发环境搭建 在搭建jeecg的maven开发环境之前,须要先配置好本机的maven环境,并在eclipse中安装好m2ecl ...
- sublime 3插件推荐
新建文件以及快速注释 1. SublimeTmpl 快速生成文件模板 一直都很奇怪为什么sublime text 3没有新建文件模板的功能,像html头部的DTD声明每次都要复制粘贴.用Subli ...
- Mocks Aren't Stubs
Mocks Aren't Stubs The term 'Mock Objects' has become a popular one to describe special case objects ...
- windows下vbs脚本隐藏控制台
每次想写python代码时,都需要打开IDE进行编写,并且需要创建许多小文件.如果使用jupyter就能够直接书写.但是jupyter需要手动通过控制台打开,这不够方便.通过把jupyter note ...
- Linux 内存机制【转载】
原文地址:http://blog.csdn.net/tianlesoftware/article/details/5463790 一. 内存使用说明 Free 命令相对于top 提供了更简洁的查看系统 ...
- 11G新特性 -- 分区表和增量统计信息
对于分区表,优化器会在全局级别为整个表维护一份统计信息,也会在分区级别为分区表维护一份统计信息. 对于大多数分区,dml一般都是在最近的分区上执行.在11g中,数据库支持只对那些发生一定数据变化的分区 ...
- Visual Studio 由于缺少调试目标
问题背景 Visual Studio启动winform项目时提示:由于缺少调试目标,Visual Studio 无法开始调试. 解决方法 解决方案配置 → 配置管理器 → 勾选[生成]选项 End C ...