We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6be6594 commit 33dacc7Copy full SHA for 33dacc7
chaoxi/Matplotlib_3D/Matplotlib_line.py
@@ -0,0 +1,31 @@
1
+import numpy as np
2
+import matplotlib.pyplot as plt
3
+from mpl_toolkits.mplot3d import Axes3D
4
+
5
+# 依次获取画布和绘图区并创建 Axes3D 对象
6
+fig = plt.figure()
7
+ax = fig.gca(projection='3d')
8
9
+# 第一条3D线性图数据
10
+theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
11
+z1 = np.linspace(-2, 2, 100)
12
+r = z1**2 + 1
13
+x1 = r * np.sin(theta)
14
+y1 = r * np.cos(theta)
15
16
+# 第二条3D线性图数据
17
+z2 = np.linspace(-3, 3, 100)
18
+x2 = np.sin(z2)
19
+y2 = np.cos(z2)
20
21
+# 绘制3D线性图
22
+ax.plot(x1, y1, z1, color='b', label='3D Line1')
23
+ax.plot(x2, y2, z2, color='r', label='3D Line2')
24
25
+# 设置标题、轴标签、图例,也可以直接使用 plt.title、plt.xlabel、plt.legend...
26
+ax.set_title('3D Line View', pad=15, fontsize='10')
27
+ax.set_xlabel('x ', color='r', fontsize='14')
28
+ax.set_ylabel('y ', color='g', fontsize='14')
29
+ax.set_zlabel('z ', color='b', fontsize='14')
30
+ax.legend()
31
+plt.show()
chaoxi/Matplotlib_3D/matplotlib_3d.py
@@ -0,0 +1,34 @@
+from matplotlib import cm
+from matplotlib.ticker import LinearLocator, FormatStrFormatter
+# 指定图形类型是 3d 类型
+ax = fig.add_subplot(projection='3d')
+# 构造数据
+X = np.arange(-5, 5, 0.25)
+Y = np.arange(-5, 5, 0.25)
+X, Y = np.meshgrid(X, Y)
+R = np.sqrt(X**2 + Y**2)
+Z = np.sin(R)
+# Plot the surface.
+surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm,
+ linewidth=0, antialiased=False)
+# Customize the z axis.
+ax.set_zlim(-1.01, 1.01)
+ax.zaxis.set_major_locator(LinearLocator(10))
+ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
+# Add a color bar which maps values to colors.
+fig.colorbar(surf, shrink=0.5, aspect=5)
32
33
34
chaoxi/Matplotlib_3D/matplotlib_3d1.py
@@ -0,0 +1,30 @@
+# 指定图形类型为 3d 类型
+ax = fig.add_subplot(111, projection='3d')
+# X, Y value
+# 设置 x-y 平面的网格
+R = np.sqrt(X ** 2 + Y ** 2)
+# height value
+# rstride:行之间的跨度 cstride:列之间的跨度
+# rcount:设置间隔个数,默认50个,ccount:列的间隔个数 不能与上面两个参数同时出现
+#vmax和vmin 颜色的最大值和最小值
+ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=plt.get_cmap('rainbow'))
+# zdir : 'z' | 'x' | 'y' 表示把等高线图投射到哪个面
+# offset : 表示等高线图投射到指定页面的某个刻度
+ax.contourf(X,Y,Z,zdir='z',offset=-2)
+# 设置图像z轴的显示范围,x、y轴设置方式相同
+ax.set_zlim(-2,2)
chaoxi/Matplotlib_3D/matplotlib_diagram.py
@@ -0,0 +1,27 @@
+def randrange(n, vmin, vmax):
+ return (vmax - vmin) * np.random.rand(n) + vmin
+n = 100
+# For each set of style and range settings, plot n random points in the box
+# defined by x in [23, 32], y in [0, 100], z in [zlow, zhigh].
+for c, m, zlow, zhigh in [('r', 'o', -50, -25), ('b', '^', -30, -5)]:
+ xs = randrange(n, 23, 32)
+ ys = randrange(n, 0, 100)
+ zs = randrange(n, zlow, zhigh)
+ ax.scatter(xs, ys, zs, c=c, marker=m)
+ax.set_title('3D Diagram View', pad=15, fontsize='10')
chaoxi/Matplotlib_3D/review_2d.py
@@ -0,0 +1,29 @@
+import matplotlib.path as mpath
+import matplotlib.patches as mpatches
+fig, ax = plt.subplots()
+Path = mpath.Path
+# Path 控制坐标点绘制贝塞尔曲线
+# 图形数据构造
+path_data = [
+ (Path.MOVETO, (1.88, -2.57)),
+ (Path.CURVE4, (0.35, -1.1)),
+ (Path.CURVE4, (-1.75, 1.5)),
+ (Path.CURVE4, (0.375, 2.0)),
+ (Path.LINETO, (0.85, 1.15)),
+ (Path.CURVE4, (2.2, 3.2)),
+ (Path.CURVE4, (3, 0.05)),
+ (Path.CURVE4, (2.0, -1.5)),
+ (Path.CLOSEPOLY, (1.58, -2.57)),
+ ]
+codes,verts = zip(*path_data)
+path = mpath.Path(verts, codes)
+patch = mpatches.PathPatch(path, facecolor='r', alpha=0.5)
+ax.add_patch(patch)
+# plot control points and connecting lines
+x, y = zip(*path.vertices)
+line, = ax.plot(x, y, 'go-')
+ax.grid()
+ax.axis('equal')
chaoxi/README.md
@@ -6,8 +6,8 @@
+ [send_email](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/send_email) :今天,我用 Python 给武汉人民发一封邮件
+ [Earth_view](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/Earth_view) :如何用 Python 制作地球仪?
+ [twoai_chat](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/twoai_chat) :两个机器人在一起会碰撞出怎样的的火花?
++ [Matplotlib_3D](https://github.com/JustDoPython/python-examples/tree/master/chaoxi/Matplotlib_3D) :Python 30 行代码画各种 3D 图形
-twoai_chat
---
从小白到工程师的学习之路
0 commit comments