Download Stack/Stack_4fbcc36f8ac870bb/code_edit.py from AIHero123/ChartM3: direct link, hf CLI and curl.
- Browser
- Download file 1.24 kB
-
https://huggingface.co/datasets/AIHero123/ChartM3/resolve/main/Stack/Stack_4fbcc36f8ac870bb/code_edit.py
- Command line
-
hf download hf://datasets/AIHero123/ChartM3/Stack/Stack_4fbcc36f8ac870bb/code_edit.py
-
curl -L -o code_edit.py https://huggingface.co/datasets/AIHero123/ChartM3/resolve/main/Stack/Stack_4fbcc36f8ac870bb/code_edit.py
1.24 kB
| 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']: | |
| stack = ax.stackplot(['Country A', 'Country B', 'Country C', 'Country D'], | |
| [data[period][pollutant] for pollutant in pollutants], labels=pollutants) | |
| if period == 'lockdown': # Apply modifications to the lockdown period | |
| for i, area in enumerate(stack): | |
| if i == 2: # PM2.5's stack | |
| area.set_clip_on(False) | |
| area.set_facecolor('#613f0e') | |
| 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("Edit_figure.png") |