【发布时间】:2016-08-03 02:46:29
【问题描述】:
我正在使用下面的代码绘制一条有两个斜率的线,如图所示。斜率应该在一定限制后下降 [limit=5]。我正在使用矢量化方法来设置斜率值。有没有其他方法来设置斜率值。有人可以帮我吗?
import matplotlib.pyplot as plt
import numpy as np
#Setting the condition
L=5 #Limit
m=1 #Slope
c=0 #Intercept
x=np.linspace(0,10,1000)
#Calculate the y value
y=m*x+c
#plot the line
plt.plot(x,y)
#Set the slope values using vectorisation
m[(x<L)] = 1.0
m[(x>L)] = 0.75
# plot the line again
plt.plot(x,y)
#Display with grids
plt.grid()
plt.show()
【问题讨论】:
标签: python numpy matplotlib