Python Matplotlib 绘制面霜销量条形图:图例、标题、轴标签和网格
import matplotlib.pyplot as plt
# 数据
months = [1, 2, 3, 4, 5, 6]
face_cream_sales = [2500, 3800, 2900, 4100, 5000, 3800]
# 绘图
plt.figure(figsize=(8, 6))
plt.bar(months, face_cream_sales, color='skyblue')
# 图例
plt.legend(['Face Cream'], loc='upper left')
# 图题
plt.title('图三:洗面奶和面霜售卖量对比条形图')
# X轴标签
plt.xlabel('Month Number')
# Y轴标签
plt.ylabel('Sales Units in Number')
# 背景网格
plt.grid(axis='y', linestyle='-')
# 显示图形
plt.show()
原文地址: https://www.cveoy.top/t/topic/bPXU 著作权归作者所有。请勿转载和采集!