如何绘制2d平面,x轴范围从0到1,y轴范围从0到1,z轴0

时间:2019-07-07 09:59:37

标签: python matplotlib

我正在尝试绘制this之类的3d向量空间

这是代码

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.quiver(0, 0, 0, 0, 1, 0)
ax.quiver(0, 0, 0, 1, 0, 0)
ax.quiver(0, 0, 0, 0, 0, 1)
ax.quiver(0, 0, 0, 1, 1, 1)

limt = 2
ax.set_xlim([-limt, limt])
ax.set_ylim([-limt, limt])
ax.set_zlim([-limt, limt])

ax.set_xlabel('x_axis')
ax.set_ylabel('y_axis')
ax.set_zlabel('z_axis')
plt.show()

enter image description here

我已经完成了矢量(带有箭头的线)部分,如何绘制2d平面x轴范围从0到1,y轴范围从0到1,z轴0?

1 个答案:

答案 0 :(得分:1)

plot_surface可能满足您的需求。

xx, yy = np.meshgrid(np.arange(0,1,.1), np.arange(0,1,.1))
zz = np.zeros((10,10))
ax.plot_surface(xx, yy, zz, alpha=0.5)

enter image description here