Python Matplotlib 绘制销售数据线图:添加趋势线、图例、标题和轴标签
您可以使用 matplotlib 库来绘制线图,并设置相应的属性来满足要求。以下是一个示例代码:
import matplotlib.pyplot as plt
# 数据
month_number = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
total_profit = [10000, 12000, 15000, 13000, 16000, 14000, 18000, 17000, 19000, 20000, 23000, 22000]
# 绘制线图
plt.plot(month_number, total_profit, linestyle='dashed', color='red', marker='o', markersize=8, linewidth=3)
# 添加图例
plt.legend(['Total Profit'])
# 添加图题
plt.title('图一:全年公司售卖数据')
# 添加轴标签
plt.xlabel('Month Number')
plt.ylabel('Sold units number')
# 显示图形
plt.show()
运行以上代码,即可得到符合要求的线图。
原文地址: https://www.cveoy.top/t/topic/bTcy 著作权归作者所有。请勿转载和采集!