Download Stack/Stack_22aeb7202160717d/code_edit.py from AIHero123/ChartM3: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/datasets/AIHero123/ChartM3/resolve/main/Stack/Stack_22aeb7202160717d/code_edit.py
- Command line
-
hf download hf://datasets/AIHero123/ChartM3/Stack/Stack_22aeb7202160717d/code_edit.py
-
curl -L -o code_edit.py https://huggingface.co/datasets/AIHero123/ChartM3/resolve/main/Stack/Stack_22aeb7202160717d/code_edit.py
1.13 kB
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| # Initialize data | |
| years = np.array(range(2010, 2020)) | |
| temperature = np.array([-20, -19, -18, -17, -16, -15, -14, -13, -12, -11]) | |
| species_a = np.array([50, 50, 49, 48, 47, 46, 45, 44, 43, 42]) | |
| species_b = np.array([80, 78, 75, 73, 70, 68, 65, 63, 60, 57]) | |
| # Create a figure and a set of subplots | |
| fig, ax1 = plt.subplots() | |
| # Plotting temperature | |
| ax1.plot(years, temperature, color="black", label="Temperature") | |
| ax1.set_xlabel("Year") | |
| ax1.set_ylabel("Temperature (°C)") | |
| ax1.tick_params('y') | |
| # Instantiate a second axes that shares the same x-axis | |
| ax2 = ax1.twinx() | |
| # Plotting populations | |
| stacks = ax2.stackplot(years, [species_a, species_b], labels=['Species A', 'Species B'], alpha=0.6) | |
| for idx, stack in enumerate(stacks): | |
| if idx in [1]: | |
| stack.set_hatch('*') | |
| stack.set_edgecolor('#e647d9') | |
| stack.set_linestyle('solid') | |
| ax2.set_ylabel("Population (in thousands)") | |
| ax2.tick_params('y') | |
| # Adding a legend | |
| fig.legend(loc="upper left", bbox_to_anchor=(0,1), bbox_transform=ax1.transAxes) | |
| # Show the plot | |
| plt.tight_layout() | |
| plt.savefig("Edit_figure.png") |