@@ -1211,6 +1211,7 @@ Plot
1211
1211
``` python
1212
1212
# $ pip3 install matplotlib
1213
1213
from matplotlib import pyplot
1214
+
1214
1215
pyplot.plot(< data_1> [, < data_2> , ... ])
1215
1216
pyplot.show()
1216
1217
pyplot.savefig(< filename> , transparent = True )
@@ -1223,6 +1224,7 @@ Progress Bar
1223
1224
# $ pip3 install tqdm
1224
1225
from tqdm import tqdm
1225
1226
from time import sleep
1227
+
1226
1228
for i in tqdm(range (100 )):
1227
1229
sleep(0.02 )
1228
1230
for i in tqdm([1 , 2 , 3 ]):
@@ -1237,6 +1239,7 @@ Table
1237
1239
# $ pip3 install tabulate
1238
1240
import csv
1239
1241
from tabulate import tabulate
1242
+
1240
1243
with open (< filename> , newline = ' ' ) as csv_file:
1241
1244
reader = csv.reader(csv_file, delimiter = ' ;' )
1242
1245
headers = [a.title() for a in next (reader)]
@@ -1273,6 +1276,7 @@ Image
1273
1276
``` python
1274
1277
# $ pip3 install pillow
1275
1278
from PIL import Image
1279
+
1276
1280
width, height = 100 , 100
1277
1281
img = Image.new(' L' , (width, height), ' white' )
1278
1282
img.putdata([255 * a/ (width* height) for a in range (width* height)])
@@ -1292,6 +1296,7 @@ Audio
1292
1296
#### Saves a list of floats with values between 0 and 1 to a WAV file:
1293
1297
``` python
1294
1298
import wave, struct
1299
+
1295
1300
frames = [struct.pack(' h' , int ((a- 0.5 )* 60000 )) for a in < list > ]
1296
1301
wf = wave.open(< filename> , ' wb' )
1297
1302
wf.setnchannels(1 )
@@ -1429,6 +1434,7 @@ timeit('"-".join(str(a) for a in range(100))',
1429
1434
# $ pip3 install pycallgraph
1430
1435
from pycallgraph import output, PyCallGraph
1431
1436
from datetime import datetime
1437
+
1432
1438
graph = output.GraphvizOutput()
1433
1439
time_str = datetime.now().strftime(' %Y%m%d %H%M%S' )
1434
1440
graph.output_file = f ' profile- { time_str} .png '
0 commit comments