import numpy as np import matplotlib.pyplot as plt R = 1.0 E0 = 1.0 r = np.linspace(0, 2.5*R, 500) E = np.where(r <= R, E0 * r / R, E0 * (R**2) / (r**2)) # plot plt.plot(r, E) plt.xlabel("r") plt.ylabel("E(r)") plt.grid(True) plt.savefig("5.png", dpi=300, bbox_inches="tight") plt.show()