python使用Matplotlib绘制分段函数 python使用Matplotlib绘制分段函数
roguesir 人气:0环境
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()
输出
加载全部内容