Download Stack/Stack_243df181c976beae/code_edit.py from AIHero123/ChartM3: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/datasets/AIHero123/ChartM3/resolve/main/Stack/Stack_243df181c976beae/code_edit.py
- Command line
-
hf download hf://datasets/AIHero123/ChartM3/Stack/Stack_243df181c976beae/code_edit.py
-
curl -L -o code_edit.py https://huggingface.co/datasets/AIHero123/ChartM3/resolve/main/Stack/Stack_243df181c976beae/code_edit.py
1.03 kB
| import matplotlib.pyplot as plt | |
| import matplotlib.patheffects as path_effects | |
| from random import choice | |
| # Define years and yield data | |
| years = list(range(2010, 2020)) | |
| wheat = [2.5, 2.4, 2.6, 2.3, 2.2, 2.1, 2.0, 1.8, 1.7, 1.5] | |
| rice = [3.2, 3.0, 2.8, 2.7, 2.6, 2.4, 2.3, 2.1, 2.0, 1.8] | |
| maize = [4.0, 3.8, 3.5, 3.3, 3.0, 2.8, 2.5, 2.3, 2.2, 2.0] | |
| # Create stack plot | |
| plt.figure(figsize=(10,7)) | |
| plt.stackplot(years, wheat, rice, maize, labels=['Wheat', 'Rice', 'Maize'], alpha=0.7) | |
| for i, area in enumerate(plt.gca().collections): | |
| if i == 1: # Rice's stack | |
| area.set_animated(True) | |
| area.set_zorder(20) | |
| shadow_color = 'gold' | |
| area.set_path_effects([path_effects.SimplePatchShadow(offset=(3.13, 3.40), shadow_rgbFace=shadow_color), path_effects.Normal()]) | |
| # Add labels and title | |
| plt.xlabel('Years') | |
| plt.ylabel('Crop yield (t/ha)') | |
| plt.title('Effects of Climate Change on Global Crop Yields (2010-2019)') | |
| plt.legend(loc='upper right') | |
| # Show the plot | |
| plt.tight_layout() | |
| plt.savefig("Edit_figure.png") |