import numpy as np
import matplotlib.pyplot as plt
#Coefficient of thermal expansion of three metals (units: /deg C)
aluminum = np.array([6.4e-5 , 3.01e-5 , 2.36e-5, 3.0e-5, 7.0e-5, 4.5e-5, 3.8e-5, 4.2e-5, 2.62e-5, 3.6e-5])
copper = np.array([4.5e-5 , 1.97e-5 , 1.6e-5, 1.97e-5, 4.0e-5, 2.4e-5, 1.9e-5, 2.41e-5 , 1.85e-5, 3.3e-5 ])
steel = np.array([3.3e-5 , 1.2e-5 , 0.9e-5, 1.2e-5, 1.3e-5, 1.6e-5, 1.4e-5, 1.58e-5, 1.32e-5 , 2.1e-5])
# Calculate the average
aluminum_mean = np.mean(aluminum)
copper_mean = np.mean(copper)
steel_mean = np.mean(steel)
# Calculate the standard deviation
aluminum_std = np.std(aluminum)
copper_std = np.std(copper)
steel_std = np.std(steel)
# Create lists for the plot
materials = ['Aluminum', 'Copper', 'Steel']
x = np.arange(len(materials))
mean = [aluminum_mean, copper_mean, steel_mean]
error = [aluminum_std, copper_std, steel_std]
# Build the plot
fig, ax = plt.subplots()
ax.bar(x, mean, yerr=error, align='center', alpha=0.5, color='green', ecolor='black', capsize=5)
ax.set_ylabel('Coefficient of Thermal Expansion ($\degree C^{-1}$)')
ax.set_xticks(x)
ax.set_xticklabels(materials)
ax.set_title('Coefficient of Thermal Expansion (CTE)')
ax.yaxis.grid(True)
# Save the figure and show
plt.tight_layout()
plt.savefig('ex297.png')
plt.show()
Like this:
Like Loading...
Related
Recent Comments