models生成

parent 4cec29ad
This diff is collapsed.
This diff is collapsed.
......@@ -9,35 +9,64 @@
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import FuncFormatter
from matplotlib.font_manager import FontProperties
def to_percent(temp, position):
return '%1.0f' % temp + '%'
def draw_stacked_column_chart():
"""堆叠柱状图"""
plt.title('Scores by group and gender')
N = 13
ind = np.arange(N) # [ 0 1 2 3 4 5 6 7 8 9 10 11 12]
plt.xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5', 'G6', 'G7', 'G8', 'G9', 'G10', 'G11', 'G12', 'G13'))
# ind = np.arange(12) # [ 0 1 2 3 4 5 6 7 8 9 10 11 12]
# plt.xticks(ind, ('M1', 'M2', 'M3', 'M4', 'M5', 'M6', 'M7', 'M8', 'M9', 'M10', 'M11', 'M12'))
#
# plt.yticks(np.arange(0, 81, 20))
#
# Bottom = (52, 49, 48, 47, 44, 43, 41, 41, 40, 38, 36, 31, 29)
# Center = (38, 40, 45, 42, 48, 51, 53, 54, 57, 59, 57, 64, 62)
# Top = (10, 11, 7, 11, 8, 6, 6, 5, 3, 3, 7, 5, 9)
#
# d = []
# for i in range(0, len(Bottom)):
# sum = Bottom[i] + Center[i]
# d.append(sum)
#
# width = 0.8 # 设置条形图一个长条的宽度
# p1 = plt.bar(ind, Bottom, width, color='blue')
# p2 = plt.bar(ind, Center, width, bottom=Bottom, color='green')
# p3 = plt.bar(ind, Top, width, bottom=d, color='red')
#
# plt.legend((p1[0], p2[0], p3[0]), ('Bottom', 'Center', 'Top'), loc=3)
#
# plt.show()
N = 5
product1 = np.array([10, 20, 30, 40, 50])
product2 = np.array([20, 20, 20, 20, 20])
product3 = np.array([20, 20, 20, 20, 20])
line = np.array([10, 15, 5, 20, 36])
ind = np.arange(N) # the x locations for the groups
width = 0.35 # the width of the bars: can also be len(x) sequence
plt.ylabel('Scores')
plt.yticks(np.arange(0, 81, 20))
p1 = plt.bar(ind, product1, width, color='#222A77', alpha=0.8)
p2 = plt.bar(ind, product2, width, bottom=product1, color='#6C71AA', alpha=0.8)
p3 = plt.bar(ind, product3, width, bottom=product2+product1, color='#E1BC95', alpha=0.8)
Bottom = (52, 49, 48, 47, 44, 43, 41, 41, 40, 38, 36, 31, 29)
Center = (38, 40, 45, 42, 48, 51, 53, 54, 57, 59, 57, 64, 62)
Top = (10, 11, 7, 11, 8, 6, 6, 5, 3, 3, 7, 5, 9)
d = []
for i in range(0, len(Bottom)):
sum = Bottom[i] + Center[i]
d.append(sum)
# plt.ylabel('Scores')
plt.title('Scores by group and gender')
plt.xticks(ind, ('G1', 'G2', 'G3', 'G4', 'G5'))
# plt.yticks(np.arange(0, 81, 10))
width = 0.35 # 设置条形图一个长条的宽度
p1 = plt.bar(ind, Bottom, width, color='blue')
p2 = plt.bar(ind, Center, width, bottom=Bottom, color='green')
p3 = plt.bar(ind, Top, width, bottom=d, color='red')
ax1 = plt.legend((p1[0], p2[0], p3[0]), ('product1', 'product2', 'product3'))
plt.legend((p1[0], p2[0], p3[0]), ('Bottom', 'Center', 'Top'), loc=3)
# 画折线图
ax2 = ax1.twinx()
line = ax2.plot(ind, line, color='#C6A774', marker='', ms=1000, label=u"总体收益")
plt.gca().yaxis.set_major_formatter(FuncFormatter(to_percent))
plt.show()
if __name__ == '__main__':
......
......@@ -8,20 +8,38 @@
# -----------------------------------------------------------------------------
import pdfkit
from PyPDF2 import PdfFileMerger, PdfFileReader, PdfFileWriter
def html_to_pdf():
options = {
'--enable-local-file-access': '--enable-local-file-access',
'encoding': "utf-8",
# 'page-size': 'A5',
'page-width': '300mm',
'page-height': '[200mm,100mm,50mm]',
# 'page-width': '300mm',
# 'page-height': '200mm',
'margin-top': '0mm',
'margin-right': '0mm',
'margin-bottom': '0mm',
'margin-left': '0mm'
}
pdfkit.from_url('https://www.taobao.com', '/Users/pengxiong/Desktop/out.pdf', options=options)
url1 = 'http://www.qimontech.com'
# url = 'http://baidu.com'
# url2 = 'https://www.cnblogs.com/zzb-yp/p/11512616.html'
# pdfkit.from_url(url1, '/Users/pengxiong/Desktop/out5.pdf', options=options)
pdfkit.from_file('/Users/pengxiong/Desktop/monthReport.html', '/Users/pengxiong/Desktop/out5.pdf', options=options)
def merge_pdf(pdfFiles, target_file='/Users/pengxiong/Desktop/combine.pdf'):
""""""
merger = PdfFileMerger()
pdfWriter = PdfFileWriter() # 生成一个空白的pdf文件
for fileName in pdfFiles:
pdfReader = PdfFileReader(open(fileName, 'rb')) # 以只读方式依次打开pdf文件
for pageNum in range(pdfReader.numPages):
print(pdfReader.getPage(pageNum))
pdfWriter.addPage(pdfReader.getPage(pageNum)) # 将打开的pdf文件内容一页一页的复制到新建的空白pdf里
pdfOutput = open(target_file, 'wb') # 生成combine.pdf文件
pdfWriter.write(pdfOutput) # 将复制的内容全部写入combine.pdf
if __name__ == '__main__':
html_to_pdf()
# merge_pdf(['/Users/pengxiong/Desktop/out1.pdf', '/Users/pengxiong/Desktop/out.pdf'])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment