最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
python使用Matplotlib绘制分段函数
时间:2018-09-28 编辑:猪哥 来源:一聚教程网
本文实例为大家分享了python使用Matplotlib绘制分段函数的具体代码,供大家参考,具体内容如下
环境
Python3
Mac OS
代码
# coding:utf-8 """ Author: roguesir Date: 2017/8/30 GitHub: https://roguesir.github.com Blog: http://blog.csdn.net/roguesir """ import numpy as np import matplotlib.pyplot as plt def sgn(value): if value < 4: return 20 else: return 15 plt.figure(figsize=(6,4)) x = np.linspace(0, 8, 100) y = np.array([]) for v in x: y = np.append(y,np.linspace(sgn(v),sgn(v),1)) l=plt.plot(x,y,'b',label='type') plt.legend() plt.show()
输出
-
下一个: python绘制多个曲线的折线图
相关文章
- Golang ProtoBuf的基本语法详解 10-20
- Python识别MySQL中的冗余索引解析 10-20
- Python+Pygame绘制小球代码展示 10-18
- Python中的数据精度问题介绍 10-18
- Python随机值生成的常用方法介绍 10-18
- python3解压缩.gz文件分析 09-27