Untitled
unknown
plain_text
5 months ago
2.0 kB
2
Indexable
import matplotlib.pyplot as plt import numpy as np # Create figure and axis fig, ax = plt.subplots(figsize=(10, 6)) # Draw the boundary between air and glass ax.hlines(0, -1, 2, colors='black', linewidth=2) # Boundary line ax.text(0, 0.02, 'Glass', horizontalalignment='center', fontsize=12) ax.text(0, -0.1, 'Air', horizontalalignment='center', fontsize=12) # Incident ray incident_angle = 45 ax.plot([0, 1], [0, np.tan(np.radians(-incident_angle))], color='blue', linewidth=2, label='Incident Ray') ax.text(1, np.tan(np.radians(-incident_angle)) / 2, '45°', fontsize=12, color='blue', horizontalalignment='left') # Normal line ax.vlines(0, -0.5, 0.5, colors='red', linestyle='dashed', linewidth=1.5) ax.text(-0.05, 0.25, 'Normal', color='red', fontsize=12) # Refracted ray refracted_angle = 28.1 ax.plot([0, 1.5], [0, -1.5 * np.tan(np.radians(-refracted_angle))], color='green', linewidth=2, label='Refracted Ray') ax.text(1.5, -1.5 * np.tan(np.radians(-refracted_angle)) / 2, '28.1°', fontsize=12, color='green', horizontalalignment='left') # Exiting ray ax.plot([0, 2.5], [-1.5 * np.tan(np.radians(-refracted_angle)), -1.5 * np.tan(np.radians(-refracted_angle)) + 1], color='orange', linewidth=2, label='Exiting Ray') ax.text(2.5, -1.5 * np.tan(np.radians(-refracted_angle)) + 0.5, 'Displacement', fontsize=12, color='orange', horizontalalignment='left') # Adding displacement line ax.hlines(-1.5 * np.tan(np.radians(-refracted_angle)), 0, 1, colors='orange', linestyle='dotted') ax.text(0.5, -1.5 * np.tan(np.radians(-refracted_angle)) - 0.3, '1.6 mm', fontsize=12, color='orange', horizontalalignment='center') # Formatting the plot ax.set_xlim(-1, 3) ax.set_ylim(-2, 1) ax.set_xlabel('Position') ax.set_ylabel('Height') ax.set_title('Refraction of Light through a Glass Plate') ax.axhline(0, color='black', lw=2) # Ground line ax.legend() ax.grid(False) ax.axis('off') # Turn off the axis # Show the plot plt.show()
Editor is loading...
Leave a Comment