from matplotlib import font_manager, rcParams
import matplotlib.pyplot as plt
import numpy as np
# Load SimHei font
font_path = "/mnt/data/SimHei.ttf"
font_manager.fontManager.addfont(font_path)
rcParams['font.sans-serif'] = ['SimHei']
rcParams['axes.unicode_minus'] = False
years = np.array([2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025])
sales = np.array([14500, 10700, 6240, 4787, 7143, 4855, 4264, 1209, 650])
plt.figure(figsize=(11, 7))
# New advanced color gradient (Viridis colormap)
colors = plt.cm.viridis(np.linspace(0.15, 0.9, len(sales)))
bars = plt.bar(years, sales, color=colors, edgecolor='black', linewidth=1.2)
# Add sales numbers on top of bars
for bar, value in zip(bars, sales):
plt.text(bar.get_x() + bar.get_width()/2, value + max(sales)*0.015,
f"{value}", ha='center', va='bottom', fontsize=14, fontweight='bold')
plt.xlabel("年份", fontsize=18)
plt.ylabel("销量(辆)", fontsize=18)
plt.title("2017-2025年玛莎拉蒂在中国销量变化(全新配色柱状图,2025年为1-9月)", fontsize=28, fontweight='bold')
plt.xticks(years, fontsize=16)
plt.yticks(fontsize=16)
plt.grid(axis='y', linestyle='--', alpha=0.4)
plt.tight_layout()
output_path = "/mnt/data/maserati_sales_china_bar_viridis.png"
plt.savefig(output_path, dpi=300)
plt.show()
output_path