Download Stack/Stack_4fbcc36f8ac870bb/code.py from AIHero123/ChartM3: direct link, hf CLI and curl.
- Browser
- Download file 987 Bytes
-
https://huggingface.co/datasets/AIHero123/ChartM3/resolve/main/Stack/Stack_4fbcc36f8ac870bb/code.py
- Command line
-
hf download hf://datasets/AIHero123/ChartM3/Stack/Stack_4fbcc36f8ac870bb/code.py
-
curl -L -o code.py https://huggingface.co/datasets/AIHero123/ChartM3/resolve/main/Stack/Stack_4fbcc36f8ac870bb/code.py
987 Bytes
| import matplotlib.pyplot as plt | |
| # Data for pre-lockdown and lockdown | |
| data = { | |
| "pre-lockdown": { | |
| "CO2": [1000, 1500, 800, 1200], | |
| "NO2": [100, 150, 80, 120], | |
| "PM2.5": [50, 70, 40, 60], | |
| "SO2": [20, 30, 15, 35] | |
| }, | |
| "lockdown": { | |
| "CO2": [600, 900, 500, 800], | |
| "NO2": [70, 120, 50, 90], | |
| "PM2.5": [30, 60, 20, 50], | |
| "SO2": [15, 25, 10, 30] | |
| } | |
| } | |
| pollutants = ["CO2", "NO2", "PM2.5", "SO2"] | |
| fig, ax = plt.subplots() | |
| # Create a stackplot | |
| for period in ['pre-lockdown', 'lockdown']: | |
| ax.stackplot(['Country A', 'Country B', 'Country C', 'Country D'], | |
| [data[period][pollutant] for pollutant in pollutants], labels=pollutants) | |
| ax.set_xlabel('Countries') | |
| ax.set_ylabel('Emissions in metric tons') | |
| ax.set_title('Impact of COVID-19 Lockdowns on Global Emissions') | |
| ax.legend(loc='upper right') | |
| # Set the x-axis limits | |
| ax.set_xlim('Country A', 'Country D') | |
| plt.tight_layout() | |
| plt.savefig("figure.png") |