python使用Matplotlib绘制分段函数
本文实例为大家分享了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()
输出
相关推荐
meylovezn 2020-09-15
wordmhg 2020-07-28
syThinkCool 2020-07-16
adamlovejw 2020-06-20
woxmh 2020-06-03
maybeyoucan 2020-05-17
jiahaohappy 2020-05-11
laohyx 2020-05-07
Tonybo 2020-04-27
liusarazhang 2020-04-10
tengyunjiawucom 2020-03-27
wangdaren 2020-03-27
Leonwey 2020-03-03
xinhao 2020-02-18
Jonderwu 2020-02-10
数据齿轮 2020-01-31
FrederickBala 2020-01-29
Laozizuiku 2020-01-13