python图片转txt、python做Excel表(显示时间)、python做Excel表(柱状)

python图片转txt

在这里插入图片描述
图片前后比较,因为图片是晚上拍的,效果可能欠佳

from PIL import Image
img = Image.open("D:\PyCharm实例\zihuaxiang\IMG_20190513_215846-.png")
out = img.convert("L")
out.size
width, height = out.size
out = out.resize((int(width * 0.5),int(height * 0.5)))
width, height = out.size
print(width,height)
print(out.getpixel((100,100)))
print(out.getpixel((200,200)))
asciis = "@%#+=-. "
texts = " "
for row in range(height):
    for col in range(width):
        gray = out.getpixel((col,row))
        texts += asciis[int(gray / 255 * 2)]
    texts += "\n"
with open("D:/PyCharm实例/zihuaxiang/new2.txt","w") as file:
    file.write(texts)

python做Excel表(显示时间)

在这里插入图片描述

import openpyxl
import datetime
wb = openpyxl.Workbook()
ws = wb.active
ws.title
ws['A1'] = 520
ws.append([1,2,3])
ws['A3'] = datetime.datetime.now()
wb.save('time.xlsx')

python做Excel表(柱状)

在这里插入图片描述

from openpyxl import Workbook
from openpyxl.chart import BarChart,Series,Reference

wb = Workbook(write_only=True)
ws = wb.create_sheet()

rows = [
    ['Number','Batch 1','Batch 2'],
    [2, 30, 40],
    [3, 25, 40],
    [4, 30, 50],
    [5, 10, 30],
    [6, 5, 25],
    [7, 10, 50],
]

for row in rows:
    ws.append(row)

chart1 = BarChart()
chart1.type = "col"
chart1.style = 10
chart1.title = "Bar Chart"
chart1.y_axis.title = 'Test number'
chart1.x_axis.title = 'Sample length (mm)'

data = Reference(ws, min_col=2, min_row=1,max_col=7, max_row=3)
cats = Reference(ws, min_col=1, min_row=2, max_row=7)
chart1.add_data(data,titles_from_data=True)
chart1.set_categories(cats)
chart1.shape = 4
ws.add_chart(chart1,"A10")

from copy import deepcopy

chart2 = deepcopy(chart1)
chart2.style = 11
chart2.type = "bar"
chart2.title = "Horizontal Bar Chart"

ws.add_chart(chart2,"J10")

chart3 = deepcopy(chart1)
chart3.type = "col"
chart3.stype = 12
chart3.grouping = "stacked"
chart3.overlap = 100
chart3.title = 'Stacked Chart'

ws.add_chart(chart3,"A27")


chart4 = deepcopy(chart1)
chart4.type = "bar"
chart4.style = 13
chart4.grouping = "percentStacked"
chart4.overlap = 100
chart4.title = 'Percent Stacked Chart'

ws.add_chart(chart4,"J27")

wb.save("bar.xlsx")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

学习微站公众平台

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值