Untitled
unknown
plain_text
a year ago
974 B
4
Indexable
import matplotlib.pyplot as plt # Data for the chart countries = ['United Kingdom', 'China', 'United States', 'Russian Federation', 'Qatar'] emissions_1990 = [9.8, 1.9, 19.4, 14.6, 28.4] emissions_2020 = [4.6, 7.8, 13.0, 11.1, 31.7] # Creating the bar chart fig, ax = plt.subplots(figsize=(12, 6)) bar_width = 0.35 index = range(len(countries)) bar1 = plt.bar(index, emissions_1990, bar_width, label='1990', color='b') bar2 = plt.bar([i + bar_width for i in index], emissions_2020, bar_width, label='2020', color='r') plt.xlabel('Country') plt.ylabel('CO2 Emissions per Capita (Metric Tonnes)') plt.title('CO2 Emissions per Capita (1990 vs 2020)') plt.xticks([i + bar_width / 2 for i in index], countries) plt.legend() # Adding percentage change labels for i in range(len(countries)): change = (emissions_2020[i] - emissions_1990[i]) / emissions_1990[i] * 100 plt.text(i, max(emissions_1990[i], emissions_2020[i]) + 1, f'{change:.1f}%', ha='center') plt.show()
Editor is loading...
Leave a Comment