Download Stack/Stack_363b2eb1a050329e/code_edit.py from AIHero123/ChartM3: direct link, hf CLI and curl.
- Browser
- Download file 1.01 kB
-
https://huggingface.co/datasets/AIHero123/ChartM3/resolve/main/Stack/Stack_363b2eb1a050329e/code_edit.py
- Command line
-
hf download hf://datasets/AIHero123/ChartM3/Stack/Stack_363b2eb1a050329e/code_edit.py
-
curl -L -o code_edit.py https://huggingface.co/datasets/AIHero123/ChartM3/resolve/main/Stack/Stack_363b2eb1a050329e/code_edit.py
1.01 kB
| import matplotlib.pyplot as plt | |
| years = ['Year 1', 'Year 2', 'Year 3', 'Year 4', 'Year 5'] | |
| # Percentages of market shares | |
| apple = [40, 35, 30, 28, 25] | |
| samsung = [30, 28, 25, 24, 23] | |
| xiaomi = [15, 20, 22, 20, 18] | |
| huawei = [10, 12, 13, 15, 17] | |
| others = [5, 5, 10, 13, 17] | |
| # Stacking each brand's market share on top of the other | |
| plt.stackplot(years, apple, samsung, xiaomi, huawei, others, | |
| colors=['green','blue','orange','red','gray'], | |
| labels=['Apple', 'Samsung', 'Xiaomi', 'Huawei', 'Others']) | |
| # Modify the color and linestyle of the target object | |
| for i, area in enumerate(plt.gca().collections): | |
| if i == 2: # Xiaomi's stack | |
| area.set_facecolor('#4bdba6') | |
| area.set_linestyle('dotted') | |
| # Title and labels | |
| plt.title('Market Share of Top-Selling Smartphone Brands Over Five Years') | |
| plt.xlabel('Year') | |
| plt.ylabel('Market Share (%)') | |
| # Positioning the legend | |
| plt.legend(loc='upper left') | |
| # Show the plot | |
| plt.tight_layout() | |
| plt.savefig("Edit_figure.png") |