import numpy as np
import matplotlib.pyplot as plt
iext = 70
v0 = 0.005
X = np.linspace(- 40 , 40 , 2000 )
Y = []
graphite = '#3C4C4C'
if iext == 70 :
for x in X:
if (x < - 25.0 ):
Y.append(- v0 / 10.0 * (x + 30.0 )** 2 + 20 * v0)
elif (x < - 15.0 ):
Y.append(- v0 * x - 7.5 * v0)
elif (x < 15.0 ):
Y.append(v0 * x** 2 / 30.0 )
elif (x < 25.0 ):
Y.append(v0 * x - 7.5 * v0)
else :
Y.append(- v0 / 10.0 * (x - 30.0 )** 2 + 20 * v0)
fig, ax = plt.subplots()
ax.plot(X, Y, c= '#965F77' , linewidth= 6 )
ax.set_ylim([- .003 , 1.05 * max ((- v0 / 10.0 * (X + 30.0 )** 2 + 20 * v0))])
ymax = max ((- v0 / 10.0 * (X + 30.0 )** 2 + 20 * v0))
# -40 -> -25 range
x1 = min (X) - (min (X) + 25 ) / 2
ax.axvline(x= min (X), linestyle= 'dashed' ,
color= graphite, linewidth= 4 , alpha= 0.3 )
ax.text(x= x1, y= ymax/ 3 ,
s= r'$-\frac {v_0}{10} \left(x + 30\right)^2 + 20 v_0$' , rotation= 90 , size= 18 )
# -25 -> -15 range
x2 = (- 25 - 15 ) / 2
ax.axvline(x=- 25 , linestyle= 'dashed' ,
color= graphite, linewidth= 4 , alpha= 0.3 )
ax.text(x= x2, y= ymax/ 4 , s= r'$-v_0 * x - 7.5 * v_0$' , rotation= 90 , size= 18 )
# -15 -> +15 range
x3 = 0
ax.axvline(x=- 15 , linestyle= 'dashed' ,
color= graphite, linewidth= 4 , alpha= 0.3 )
ax.text(x= x3, y= ymax/ 3 , s= r'$v_0 * \frac{x^2} {30} $' , rotation= 90 , size= 18 )
ax.axvline(x= 15 , linestyle= 'dashed' ,
color= graphite, linewidth= 4 , alpha= 0.3 )
# 15 -> 25 range
x4 = (25 + 15 ) / 2
ax.axvline(x= 25 , linestyle= 'dashed' ,
color= graphite, linewidth= 4 , alpha= 0.3 )
ax.text(x= x4, y= ymax/ 4 , s= r'$v_0 * x - 7.5 * v_0$' , rotation= 90 , size= 18 )
# 25 -> 40 range
x5 = max (X) - (max (X) - 25 ) / 2
ax.axvline(x= min (X), linestyle= 'dashed' ,
color= graphite, linewidth= 4 , alpha= 0.3 )
ax.text(x= x5, y= ymax/ 3 ,
s= r'$-\frac {v_0}{10} \left(x - 30\right)^2 + 20 v_0$' , rotation= 90 , size= 18 )
ax.axvline(x= max (X), linestyle= 'dashed' ,
color= graphite, linewidth= 4 , alpha= 0.3 )
for axis in ['top' , 'bottom' , 'left' , 'right' ]:
ax.spines[axis].set_linewidth(3 )
ax.tick_params(length= 10 , width= 2.5 )
ax.set_xlim(- 40 ,40 )
for label in (ax.get_xticklabels() + ax.get_yticklabels()):
label.set_fontsize(16 )
plt.show()