问题:
**使用for 循环,依次绘制出每一个RESTAURANT_ID的订单数量ORDER_ID与当年相应周数WEEK_COUNT的折线图。
**
变量描述:
WEEK_COUNT是周数,从 1 到 52;
RESTAURANT_ID 有 R10001 到 R10008;
代码实现的效果:
横轴:WEEK_COUNT
纵轴:ORDER_ID
然后使用for 循环绘制8张折线图,对应8个RESTAURANT_ID(分别是R10001 到 R10008)
下图是我分组统计频数的结果。
总结:
如何实现这个效果呢?
```python
import xlrd
import matplotlib.pyplot as plt
book = xlrd.open_workbook(r'C:\Users\Administrator\Desktop\cheng_ji.xlsx') # 获取工作表格
sheet2 = book.sheets()[1] # 获取表格sheet
col0_value = sheet2.col_values(0, 1) # 获取学生姓名列表
col1_value = sheet2.col_values(1, 1) # 获取sheet第2列成绩列表
col2_value = sheet2.col_values(2, 1) # 获取sheet第3列成绩列表
col_dict = zip(col1_value, col2_value) # 将姓名和成绩存为字典以便于遍历
while '' in col0_value:
col0_value.remove('')
n = []
r = []
t = []
for index, i in enumerate(col0_value):
n.append(i)
plt.subplot(2, 6, len(n))
plt.title(i, fontsize=10, color='blue')
plt.ylabel('ORDER_ID')
plt.xlabel('WEEK_COUNT')
r = col1_value[index * 5:index * 5 + 5]
t = col2_value[index * 5:index * 5 + 5]
plt.subplots_adjust(left=0.1, bottom=0.1, top=0.9, wspace=0.8, hspace=0.5)
plt.plot(r, t, 'r-')
plt.show()
```