-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWeekly-work006-Maplot
More file actions
91 lines (85 loc) · 2.7 KB
/
Copy pathWeekly-work006-Maplot
File metadata and controls
91 lines (85 loc) · 2.7 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
89
90
91
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.image as mping
#x = np.linspace(-5, 5, 20)
#y = x**2 + 1
#plt.plot(x, y)#绘制数据
'''
plt.plot(x, y,
color='green',#点之间线段颜色
linestyle='dashed',#线段的类型
marker= 'o',#数据点的绘制方式
markerfacecolor= 'blue',#数据点的颜色
markersize= 12#数据大小
)'''
'''
plt.plot(x, y, "r:x",#简写定制:红色点状线段x号数据点
x+3, y, "b-D",
x+6, y, "y--_")
'''
#subplot布局
'''ax1 = plt.subplot(2 ,2, 1)
ax2 = plt.subplot(4, 4, 4)
#ax3 = plt.subplot(2 ,2, 3)
#ax4 = plt.subplot(2 ,2, 4)
'''
#subplot2grid布局
'''ax1 = plt.subplot2grid(shape=(3, 3), loc=(0, 0), colspan=2)
ax2 = plt.subplot2grid(shape=(3, 3), loc=(1, 0), colspan=2)
ax3 = plt.subplot2grid(shape=(3, 3), loc=(0, 2), rowspan=2)
ax4 = plt.subplot2grid(shape=(3, 3), loc=(2, 0), colspan=3)
'''
#子视图绘制
'''ax1 = plt.subplot(1, 3, 1)
ax2 = plt.subplot(1, 3, 2)
ax3 = plt.subplot(1, 3, 3)
x = np.linspace(0, 2, 100)
ax1.plot(x, x**0.5, label="y=power(x, 0.5)")
ax1.plot(x, x**2, label="y=power(x, 2)")
ax2.plot(x, 0.5**x, label="y=power(0.5, x)")
ax2.plot(x, 2**x, label="y=power(2, x)")
ax3.plot(x, np.log2(x), label="y=log2(x)")
ax3.plot(x, np.log10(x), label="y=log10(x)")
ax1.legend()
ax2.legend()
ax3.legend()
'''
'''#图像
img = mping.imread('dog.png')
#print(img)#每个像素点由四个数值表达red,green,blue,alpha(透明度)
#plt.imshow(img)
grey_img = img[:, :, 0]
#print(grey_img)
ax1 = plt.subplot2grid(shape=(4, 4), loc=(0, 0), colspan=2, rowspan=2)
ax2 = plt.subplot2grid(shape=(4, 4), loc=(2, 0), colspan=2, rowspan=2)
ax3 = plt.subplot2grid(shape=(4, 4), loc=(0, 2), colspan=2, rowspan=2)
#ax4 = plt.subplot2grid(shape=(4, 4), loc=(2, 2), colspan=2, rowspan=2)
ax1.imshow(img)
ax2.imshow(grey_img, cmap="binary")#黑白
ax3.imshow(grey_img, cmap="winter")#蓝绿冷色调
ax4.imshow(grey_img, cmap="Spectral")#彩虹谱
plt.hist(img.ravel(), bins=256)#颜色直方图,bins为粒度,越大越精细
plt.hist(grey_img.ravel(), bins=256)
ax1.imshow(img, interpolation="nearest")
ax2.imshow(img, interpolation="bicubic")
ax3.imshow(img, interpolation="sinc")
plt.show()#显示绘图
'''
#三维绘图
ax = plt.subplot(1, 1, 1, projection='3d')#建立三维坐标系
'''#线
x = np.linspace(0, 10, 100)
y = np.linspace(-10, 0, 100)
z = np.sin(x+y)
f = np.cos(x+y)
#ax.plot(x, y, z)
#点
ax.scatter(x, y, z,c= "r", marker = ">")
ax.scatter(x, y, f,c= "b", marker = "<")'''
x = np.linspace(0, 10, 100)
y = np.linspace(0, 10, 100)
x, y = np.meshgrid(x, y)#将x,y变成2维数组
z = np.sin(x+y)
ax.plot_surface(x, y, z, cmap= "Spectral")
plt.show()