第18天-NumPy + Pandas + Matplotlib多维度直方图
示例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&#