5条曲线汇合到一张图标了,mark下
代码如下:import openpyxl as xl
import matplotlib.pyplot as plt
def get_data(path):
wb = xl.load_workbook(path,data_only=True)
ws = wb.active
max_row = ws.max_row
max_col = ws.max_column
date_lst = []
profit_lst = []
price_lst = []
sale_price_lst = []
sale_num_lst = []
profit_rate_lst = []
for row in ws.iter_rows(min_row=2,max_row=max_row,max_col=max_col):
# print(row[0].value,row[6].value)
date_lst.append(row[0].value)
profit_lst.append(row[6].value)
price_lst.append(row[2].value)
sale_price_lst.append(row[3].value)
sale_num_lst.append(row[4].value)
profit_rate_lst.append(row[5].value)
return date_lst,profit_lst,price_lst,sale_price_lst,sale_num_lst,profit_rate_lst
def chart(x,y1,y2,y3,y4,y5):
plt.plot(x,y1)
plt.plot(x,y2)
plt.plot(x,y3)
plt.plot(x,y4)
plt.plot(x,y5)
plt.show()
path = r'C:\Users\xxx\Desktop\实例.xlsx'
get_data(path)
chart(*get_data(path))
下一步:
里边把成本画成柱状图,便于和售价曲线对比看。
现在没有区分A和B商品,最好把两个商品分开,图例显示。
|