Matplotlib瞎吉儿弄的模板

(〇)实用模板

【简易模板】

1
2
3
4
5
6
7
8
9
10
11
12
from matplotlib import pyplot as plt
import matplotlib
import numpy as np
import os.path as pa
# -----------------------------------------
matplotlib.rc("font", family='Microsoft YaHei', weight='bold')
res = '../../Assets' # pa.join(res, '')
# -----------------------------------------

# -----------------------------------------
plt.show()

【折线统计图模板】

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from matplotlib import pyplot as plt
import matplotlib
import numpy as np
import os.path as pa
# -----------------------------------------
matplotlib.rc("font", family='DengXian', weight='bold')
res = '../../Assets' # pa.join(res, '')
# -----------------------------------------
arr_a = np.arange(1, 10)
arr_b = np.arange(1, 10)
# -----------------------------------------
plt.figure(figsize=(14, 6), dpi=80), plt.title("图表", size=20)
plt.plot(arr_a, arr_b, color='#442244')
# -----------------------------------------
plt.xticks(arr_a), plt.yticks(arr_b)
plt.xlim(0, len(arr_a) + 1), plt.ylim(0, max(arr_b) + 1)
plt.xlabel("x坐标", size=20), plt.ylabel("y坐标", size=20)
# -----------------------------------------
plt.show()

【条形统计图模板】

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from matplotlib import pyplot as plt
import matplotlib
import numpy as np
import os.path as pa
# -----------------------------------------
matplotlib.rc("font", family='DengXian', weight='bold')
res = '../../Assets' # pa.join(res, '')
# -----------------------------------------
arr_a = np.arange(1, 10)
arr_b = np.arange(1, 10)
# -----------------------------------------
plt.figure(figsize=(14, 6), dpi=80), plt.title("图表", size=20)
plt.bar(arr_a, arr_b, color='#886688')
# -----------------------------------------
plt.xticks(arr_a), plt.yticks(arr_b)
plt.xlim(0, len(arr_a) + 1), plt.ylim(0, max(arr_b) + 1)
plt.xlabel("x坐标", size=20), plt.ylabel("y坐标", size=20)
# -----------------------------------------
plt.show()

(一)杂项

【字体查找】

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 查询当前系统所有字体
from matplotlib.font_manager import FontManager
mpl_fonts = set(f.name for f in FontManager().ttflist)
print('all font list get from matplotlib.font_manager:')
for f in sorted(mpl_fonts):
print('\t' + f)
# 中文字体
Adobe Heiti Std
Adobe Kaiti Std
Adobe Song Std
DengXian
FZShuTi
FZYaoTi
FangSong
KaiTi
LiSu
Microsoft JhengHei
Microsoft YaHei
STCaiyun
STFangsong
STHupo
STKaiti
STLiti
STSong
STXihei
STXingkai
STXinwei
STZhongsong
SimHei
SimSun
SimSun-ExtB
Source Han Sans CN
Source Han Serif CN
YouYuan