Skip to content

Commit 4699535

Browse files
committed
rst+plotly
1 parent ab73a75 commit 4699535

30 files changed

Lines changed: 957 additions & 215 deletions

README.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,45 @@ plt.show()
749749
```
750750
![散点图](./img/scatter-plt.png)
751751

752+
#### Plotly绘图
753+
754+
1 绘制柱状图+折线图
755+
756+
```python
757+
import plotly.graph_objects as go
758+
fig = go.Figure()
759+
fig.add_trace(
760+
go.Scatter(
761+
x=[0, 1, 2, 3, 4, 5],
762+
y=[1.5, 1, 1.3, 0.7, 0.8, 0.9]
763+
))
764+
fig.add_trace(
765+
go.Bar(
766+
x=[0, 1, 2, 3, 4, 5],
767+
y=[2, 0.5, 0.7, -1.2, 0.3, 0.4]
768+
))
769+
fig.show()
770+
```
771+
772+
![1576311673983](./img/plotly1.png)
773+
774+
2 饼图
775+
776+
```python
777+
import plotly.graph_objects as go
778+
779+
labels = ['照明与插座用电', '空调用电', '动力用电', '特殊用电']
780+
values = [4500, 2500, 1053, 500]
781+
fig = go.Figure(data=[go.Pie(labels=labels, values=values)])
782+
fig.show()
783+
```
784+
785+
786+
787+
![1576311817234](./img/plotly2.png)
788+
789+
790+
752791
#### 十三、PyQt
753792

754793
1 [使用PyQt打造一款自己的计算器,仅有100行代码](./src/calculator)
@@ -786,7 +825,36 @@ print(list(descend_iter))
786825

787826
2) `raise StopIteration`:通过 raise 中断程序,必须这样写
788827

828+
#### 十五 装饰器
829+
[测试函数执行时间的函数装饰器](./md/测试函数执行时间的函数装饰器.md)
830+
```python
831+
import time
832+
def timing_func(fn):
833+
def wrapper():
834+
start=time.time()
835+
fn() #执行传入的fn参数
836+
stop=time.time()
837+
return (stop-start)
838+
return wrapper
839+
@timing_func
840+
def test_list_append():
841+
lst=[]
842+
for i in range(0,100000):
843+
lst.append(i)
844+
@timing_func
845+
def test_list_compre():
846+
[i for i in range(0,100000)] #列表生成式
847+
a=test_list_append()
848+
c=test_list_compre()
849+
print("test list append time:",a)
850+
print("test list comprehension time:",c)
851+
print("append/compre:",round(a/c,3))
852+
853+
test list append time: 0.0219423770904541
854+
test list comprehension time: 0.007980823516845703
855+
append/compre: 2.749
789856

857+
```
790858

791859

792860

img/plotly1.png

28 KB
Loading

img/plotly2.png

45.9 KB
Loading

md/1576311610044.png

28 KB
Loading

md/README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,26 +88,31 @@
8888
2. [将list等分为子组(生成器版)](将list等分为子组(生成器版).md)
8989
3. [多层列表转为单层列表](多层列表转为单层列表.md)
9090

91-
### 十、迭代器
91+
#### 十、迭代器
9292

9393
1. [递减迭代器](迭代器递减.md)
94-
2.
9594

9695

97-
#### 十一、Keras
96+
97+
#### 十一、装饰器
98+
99+
1. [测试函数执行时间的函数装饰器](测试函数执行时间的函数装饰器.md)
100+
101+
102+
#### 十二、Keras
98103
1. [Keras入门例子](Keras入门例子.md)
99104

100-
#### 十二、邮件相关
105+
#### 十三、邮件相关
101106
[20行代码实现发邮件](简单邮件.md)
102107
[发送带附件的邮件](自动群发邮件.md)
103108

104109

105-
#### 十三、Pandas
110+
#### 十四、Pandas
106111
[列分割](split_csv.py)
107112

108113
[xlsx批量合并到一个xlsx文件中](xlsx批量合并到一个xlsx文件中.md)
109114

110-
#### 十四、PyQt
115+
#### 十五、PyQt
111116

112117
[使用PyQt打造一款自己的计算器,仅有100行代码](./src/calculator2.py)
113118

md/奖金梯度计算.md

Lines changed: 0 additions & 25 deletions
This file was deleted.

md/折线+柱状图.md

Lines changed: 1 addition & 68 deletions
Large diffs are not rendered by default.

md/文件批量压缩.md

Lines changed: 18 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,28 @@
11

22

33
```python
4-
#文件压缩
5-
import zipfile #导入zipfile,这个是用来做压缩和解压的Python模块;
4+
import zipfile # 导入zipfile,这个是用来做压缩和解压的Python模块;
65
import os
76
import time
8-
def zipflie(start_dir,target_dir):
9-
today_file = target_dir + os.sep + time.strftime('%Y%m%d') #创建一个当前日期的文件夹
10-
if not os.path.exists(today_file):
11-
os.mkdir(today_file)
12-
print('Successfully created directory',today_file)
13-
for item in os.listdir(start_dir):
14-
file_news = today_file+os.sep+item+'.zip' #存放位置创建压缩后文件夹的名字
15-
z = zipfile.ZipFile(file_news,'w')
16-
#start_dir+os.sep+item代表的是要写入z的文件
17-
z.write(start_dir+os.sep+item,item) #item代表只写入文件本身而不包含其完整路径
18-
print(item)
7+
8+
9+
def batch_zip(start_dir):
10+
start_dir = start_dir # 要压缩的文件夹路径
11+
file_news = start_dir + '.zip' # 压缩后文件夹的名字
12+
13+
z = zipfile.ZipFile(file_news, 'w', zipfile.ZIP_DEFLATED)
14+
for dir_path, dir_names, file_names in os.walk(start_dir):
15+
# 这一句很重要,不replace的话,就从根目录开始复制
16+
f_path = dir_path.replace(start_dir, '')
17+
f_path = f_path and f_path + os.sep # 实现当前文件夹以及包含的所有文件的压缩
18+
for filename in file_names:
19+
z.write(os.path.join(dir_path, filename), f_path + filename)
1920
z.close()
20-
print ('压缩成功')
21+
return file_news
2122

2223

23-
start_dir = r"C:\Users\CQ375\Desktop\ex" #指定压缩文件夹路径
24-
target_dir = r"C:\Users\CQ375\Desktop\RFM" #指定压缩后存放文件夹
25-
zipflie(start_dir,target_dir)
26-
```
24+
batch_zip('./data/ziptest')
25+
2726

28-
Successfully created directory C:\Users\CQ375\Desktop\RFM\20191209
29-
440300A027.xlsx
30-
440300A029.xlsx
31-
440300A036.xlsx
32-
440300A045.xlsx
33-
440300A052.xlsx
34-
440300A059.xlsx
35-
data_result.xls
36-
test.txt
37-
test.xlsx
38-
压缩成功
27+
```
3928

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
2-
31
```python
42
#测试函数执行时间的装饰器示例
53
import time
@@ -23,11 +21,8 @@ c=test_list_compre()
2321
print("test list append time:",a)
2422
print("test list comprehension time:",c)
2523
print("append/compre:",round(a/c,3))
26-
#@timing_func修饰test_list_append意味着完成两部操作,将test_list_append作为timing_func()的参数即执行timing_func(test_list_append),然后将test_list_append替换成timing_func()返回的结果。
27-
#即被修饰的函数总是被替换成@符号所引用的函数返回值。
28-
```
2924

30-
test list append time: 0.0219423770904541
31-
test list comprehension time: 0.007980823516845703
32-
append/compre: 2.749
33-
25+
test list append time: 0.0219423770904541
26+
test list comprehension time: 0.007980823516845703
27+
append/compre: 2.749
28+
```

md/饼状图.md

Lines changed: 0 additions & 70 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)