Skip to content

Instantly share code, notes, and snippets.

@seafooler
seafooler / add-legend-manually.py
Created October 20, 2020 09:11
Add the legend manually
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
red_patch = mpatches.Patch(color='red', label='The red data')
blue_patch = mpatches.Patch(color='blue', label='The blue data')
plt.legend(handles=[red_patch, blue_patch])
@seafooler
seafooler / parse_log.py
Created October 17, 2020 17:19
Parse a experimental log in Python
#!/usr/bin/python3
import csv
data = []
filename = "log-cnn-node1"
# To deal with the lines like [epoch 1, 600 inst] Testing ACC: 0.0883, Loss: 2.3214
with open(filename+".txt", "r") as f:
@seafooler
seafooler / redirect-python-output.sh
Created September 3, 2020 06:54
Redirect&flush the python script output to a file
script -c "python test.py" -f OUTPUT.txt
@seafooler
seafooler / proxy-go-get.sh
Created December 14, 2019 08:21
Proxy settting for go get
go env -w GOPROXY=https://goproxy.cn,direct
@seafooler
seafooler / enlarge-disk-vagrant.md
Created December 14, 2019 08:18
Enlarge the disk size in vagrant VM

Install vagrant-disksize

vagrant plugin install vagrant-disksize

Modify VagrantFile

Vagrant.configure("2") do |config|
  config.vm.box = "centos/7"
 config.disksize.size = '80GB'
@seafooler
seafooler / draw-stacked-bar.py
Created November 12, 2019 17:33
Example for drawing stacked bars plot in python
import pandas as pd
import matplotlib.pyplot as plt
xticks = ['0~5', '5~10', '10~15', '15~20', '20~25', '25~30', '30~35', '35~40', '40~45', '45~49']
data1 = [39266.6454,39655.67939,39961.77618,39421.58352,45809.54727,45992.33723,46111.81729,42279.75517,47363.08822,39355.46721]
data2 = [744.3184969,580.8364771,608.6965388,599.6553536,556.4223923,386.1615846,452.205138,389.9741167,343.7995401,306.9898914]
data3 = [10016.60611,9788.374129,9461.967283,9994.091129,3664.340342,3645.11118,3461.977574,7361.090709,2341.232241,1987.660203]
index = pd.Index(xticks, name='test')
@seafooler
seafooler / draw-multiple-lines-two-y-axis.py
Created November 12, 2019 13:16
Example for drawing multiple lines with two y axises in Python
import matplotlib.pyplot as plt
xticks = ['86','87','88','89','90','91','92','93','94','95']
num_n = [1827,3194,3659,2331,214,264,3407,1961,116,1038]
num_m = [3053,6588,5766,3729,368,1621,5722,3205,152,1879]
time_p = [1056,2908.1,1910.2,1188.1,78,4284.6,2271.4,874.46,38.3645,1101.2]
time_q = [13.012,73.2918,27.5084,14.64,2.1909,4.901,24.13991,13.5521,0.7378,8.5]
@seafooler
seafooler / draw-bar-line-exp.py
Created November 7, 2019 09:54
Example for drawing a bar and a line in the same figure in Python
import matplotlib.pyplot as plt
import numpy as np
xticks = ['15-1','15-2','15-3','15-4','16-1','16-2','16-3','16-4',
'17-1','17-2','17-3','17-4','18-1','18-2','18-3','18-4','19-1','19-2','19-3']
cnt = np.array([17.17646221,19.43652252,30.54252321,32.78014989,34.46738787,37.55476953,40.99359145,42.65602493,
45.62631487,50.40547517,51.19912708,55.64568829,57.58204446,51.35193284,49.39556185,50.08214678,
50.84948824,55.20547267,60.22801956])
size = np.array([5.735962982,6.630246013,9.499133204,10.29255457,11.19376834,12.47500742,14.02777201,15.28399689,
@seafooler
seafooler / draw-bar-exp.py
Last active November 7, 2019 09:51
Example for drawing a bar in Python
import matplotlib.pyplot as plt
import numpy as np
xticks = ['15-1','15-2','15-3','15-4','16-1','16-2','16-3','16-4',
'17-1','17-2','17-3','17-4','18-1','18-2','18-3','18-4','19-1','19-2','19-3']
cnt = np.array([17.17646221,19.43652252,30.54252321,32.78014989,34.46738787,37.55476953,40.99359145,42.65602493,
45.62631487,50.40547517,51.19912708,55.64568829,57.58204446,51.35193284,49.39556185,50.08214678,
50.84948824,55.20547267,60.22801956])
@seafooler
seafooler / draw-line-exp.py
Last active November 7, 2019 09:52
Example for drawing a line chart in Python
import matplotlib.pyplot as plt
import numpy as np
xticks = ['15-1','15-2','15-3','15-4','16-1','16-2','16-3','16-4',
'17-1','17-2','17-3','17-4','18-1','18-2','18-3','18-4','19-1','19-2','19-3']
size = np.array([573.5962982,663.0246013,949.9133204,1029.255457,1119.376834,1247.500742,1402.777201,1528.399689,
1694.4369,1915.263185,2212.279345,2985.357858,3109.525989,2787.855024,2710.313029,2778.113192,
2845.668532,3114.45823,3429.272631])