In point of fact, yesterday's exercise with the costs of utility figure was not the
required output. in reality, the cost increase is an annual event, on the anniversary date.
So a bar graph is required. Below, one generated by Copilot:
The python code:
# Creating bar graph of annual utility cost with 3% yearly increase
import matplotlib.pyplot as plt
# Data
years = list(range(1, 11))
costs = [103.00, 106.09, 109.27, 112.55, 115.93, 119.41, 123.00, 126.69, 130.49, 134.39]
# Create bar chart
plt.style.use('seaborn-v0_8')
fig, ax = plt.subplots(figsize=(10, 6))
bars = ax.bar(years, costs, color='skyblue')
# Add labels on top of each bar
for bar, cost in zip(bars, costs):
height = bar.get_height()
ax.text(bar.get_x() + bar.get_width()/2, height + 1, f"${cost:.2f}", ha='center', va='bottom', fontsize=9)
# Customize chart
ax.set_title('Annual Utility Cost with 3% Yearly Increase', fontsize=14)
ax.set_xlabel('Year', fontsize=12)
ax.set_ylabel('Cost ($)', fontsize=12)
ax.set_xticks(years)
ax.set_ylim(0, max(costs) + 10)
plt.tight_layout()
# Save figure
output_path = "/mnt/data/annual_utility_cost_bar_chart.png"
plt.savefig(output_path)
plt.show()
print("Bar chart of annual utility costs saved as annual_utility_cost_bar_chart.png")
I also had a try at producing a bar chart from Geogebra:



No comments:
Post a Comment