from lxml.html import parse
from urllib.request import urlopen
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
import csv
import re
t_data = pd.read_csv('D:\\kaola\\deal_with_data\\t_data.csv',encoding='GB18030')
# 分组
gp = t_data.groupby(by=['ways'])
data = gp.size()
data = data.reset_index(name='numbers')
data = data.sort('numbers')
data = data.reset_index(drop=True)
list_way_num = []
list_way_name = []
# 将产地名称加入list_add_name列表中
for i in data['ways']:
#print(i)
list_way_name.append(i)
# 将总数加入list_add_num列表中
for i in data['numbers']:
#print(i)
list_way_num.append(i)
import matplotlib
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
#指定默认字体
# 先设置画布大小
#plt.style.use('classic')
fig = plt.figure(figsize = (20,20))
# 设置图像标题、文字大小、加粗
fig.suptitle('Sales Analysis', fontsize = 16, fontweight = 'bold')
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
matplotlib.rcParams['font.family']='sans-serif'
#x=[0,3,6,9,12,15,18,21,24,27,30,33,36,39,42,45,48,51,54,57,60]
# 绘制图形
plt.barh(range(len(list_way_num)),list_way_num,align = 'center',color='red',alpha = 0.8)
# 标题
plt.title('产地在各个国家所在的数量')
# x轴设置
plt.yticks(np.arange(36),list_way_name)
# y轴设置
#plt.xticks([0,100,200,300,400,500])
# 设置条形图所代表的数量
#for x,y in enumerate(list_way_num):
# plt.text(x,y+20,'%s'%round(y,1),ha='center')
# 折线图
#plt.plot(range(len(list_way_name)),list_way_num,marker = 'o',color='coral')
# x,y轴的说明
plt.xlabel('数量')
plt.ylabel('优惠方式')
plt.show()