-
Notifications
You must be signed in to change notification settings - Fork 26
/
chapter-12.py
74 lines (42 loc) · 1.08 KB
/
chapter-12.py
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
# coding: utf-8
# # 《python数据可视化之matplotlib实践》
#
# ## 查看颜色格式
#
# http://colorbrewer2.org/#type=sequential&scheme=PuBuGn&n=3
# In[3]:
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
random_data = np.random.rand(10,10)
plt.pcolor(random_data, cmap='BuPu') # Create a pseudocolor plot of a 2-D array.
plt.colorbar()
plt.show()
# In[4]:
random_data = np.random.rand(10,10)
plt.pcolor(random_data, cmap=mpl.cm.BuPu) # 指定颜色格式colormap的另一种方法
plt.colorbar()
plt.show()
# In[5]:
# 绘制图片的像素值colormap
import scipy.misc
import matplotlib as mpl
import matplotlib.pyplot as plt
ascent = scipy.misc.ascent() # 调用一张图像示例(numpy array格式)
print(ascent.shape, type(ascent))
plt.imshow(ascent, cmap=mpl.cm.gray)
plt.colorbar()
plt.show()
# In[6]:
plt.imshow(ascent, cmap=mpl.cm.jet)
plt.colorbar()
plt.show()
# In[7]:
plt.imshow(ascent, cmap=mpl.cm.hot)
plt.colorbar()
plt.show()
# In[8]:
demo = plt.imread("overview.png")
plt.imshow(demo)
plt.colorbar()
plt.show()