示例1:帶樣式的柱狀圖
python
復制
下載
import numpy as np import pandas as pd import matplotlib.pyplot as plt# 生成數據 df = pd.DataFrame(np.random.randint(10, 100, size=(8, 4)),columns=['Spring', 'Summer', 'Autumn', 'Winter'],index=[2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022] )# 繪制帶樣式的柱狀圖 ax = df.plot.bar(figsize=(12, 6),color=['#4CAF50', '#2196F3', '#FF9800', '#9C27B0'],edgecolor='black',width=0.8 )# 設置圖表元素 plt.title('Seasonal Sales Trends (2015-2022)', fontsize=14, pad=20) plt.xlabel('Year', labelpad=15) plt.ylabel('Sales (Million USD)', labelpad&#