import numpy as np import matplotlib.pyplot as plt height = 3 radius = 2 base_radius = 0.5 base_length = 0.3 def morph_shape(x, L, H, morph_type="linear"): y = np.ones(x.shape[0]) if morph_type == "linear": y = (x/L)*H elif morph_type == "logistic": k = 10.0 v = 1.0 y = H/(1.0 + np.power(np.exp(-k*(x-L/4.0)), v)) elif morph_type == "sinusoid": y = np.sin((x/L)*np.pi/2.0) elif morph_type == "hyperbolic_tan": y = np.tanh((x/L)*np.pi/2.0) elif morph_type == "circle": y = np.tanh((x/L)*np.pi/2.0) return y x_base = np.linspace(0, base_length, 10) y_base = base_radius*np.ones(x_base.shape[0]) x_lamp = np.linspace(base_length, height, 100) y_lamp = base_radius + morph_shape(x_lamp-base_length, height-base_length, radius-base_radius, "hyperbolic_tan") x = np.append(x_base, x_lamp) y = np.append(y_base, y_lamp) plt.plot(x, y) axes = plt.gca() axes.set_xlim([0, 1.1*base_length+height]) axes.set_ylim([0,1.1*radius]) plt.axis('equal') plt.show()