-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatplotlib_subplot.py
More file actions
97 lines (78 loc) · 2.48 KB
/
matplotlib_subplot.py
File metadata and controls
97 lines (78 loc) · 2.48 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# coding:utf-8
import numpy as np
import matplotlib.pyplot as plt
def draw_subs():
for idx, color in enumerate('rgbyck'):
plt.subplot(321+idx, axisbg=color)
plt.show()
def draw_multi_figure():
# 创建图表1
plt.figure(1, figsize=(8,5))
# 创建图表2
plt.figure(2, figsize=(8,5))
# 在图表2中创建子图1
sub_1 = plt.subplot(211)
# 在图表2中创建子图2
sub_2 = plt.subplot(212)
# sca = set the current axes
# sca(ax) set the current axes instance to *ax*
x = np.linspace(0, 3, 100)
for i in xrange(5):
# 选择图表1
plt.figure(1)
plt.plot(x, np.exp(i*x/3))
# 选择图表2中的子图1
plt.sca(sub_1)
plt.plot(x, np.sin(i*x))
plt.sca(sub_2)
plt.plot(x, np.cos(i*x))
plt.show()
# 显示所有中文字体
from matplotlib.font_manager import fontManager
import os
import os.path
def show_all_chinese():
fig = plt.figure(figsize=(12, 6))
ax = fig.add_subplot(111)
plt.subplots_adjust(0, 0, 1, 1, 0, 0)
plt.xticks([])
plt.yticks([])
x, y = 0.05, 0.08
# 找出路径中大于1M的中文字体
fonts = [font.name for font in fontManager.ttflist if os.path.exists(font.fname) and os.stat(font.fname).st_size>1e6]
# 将fonts放到集合当中进行排序
font = set(fonts)
print(len(fonts))
dy = (1.0-y) / (len(fonts) / 4 + (len(fonts) % 4 != 0))
for font in fonts:
t = ax.text(x, y, u"中文字体", {'fontname':font, 'fontsize':14}, transform=ax.transAxes)
ax.text(x, y - dy / 2, font, transform=ax.transAxes)
x += 0.25
if x >= 1.0:
y += dy
x = 0.05
plt.show()
def show_all_ch():
fig = plt.figure(figsize=(12, 6))
ax = fig.add_subplot(111)
plt.subplots_adjust(0, 0, 1, 1, 0, 0)
plt.xticks([])
plt.yticks([])
x, y = 0.05, 0.08
fonts = [font.name for font in fontManager.ttflist if
os.path.exists(font.fname) and os.stat(font.fname).st_size > 1e6]
font = set(fonts)
dy = (1.0 - y) / (len(fonts) / 4 + (len(fonts) % 4 != 0))
for font in fonts:
t = ax.text(x, y, u"中文字体", {'fontname': font, 'fontsize': 14}, transform=ax.transAxes)
ax.text(x, y - dy / 2, font, transform=ax.transAxes)
x += 0.25
if x >= 1.0:
y += dy
x = 0.05
plt.show()
if __name__ == "__main__":
# draw_subs()
# draw_multi_figure()
show_all_chinese()
# show_all_ch()