通过Python创建带有2个平面和颜色图的图形

时间:2019-02-13 23:19:45

标签: python graph

我有两个2D数组,我想用它来产生类似于休憩的图像,只是在轴上有不同的限制。

enter image description here

到目前为止,这是我的尝试:

Public class MyClass extends superclass

我拥有的数组(array1和array2)是二维的,大小为n×n。任何帮助或朝着正确方向的观点将不胜感激!

1 个答案:

答案 0 :(得分:1)

借助Matplotlib - Plot a plane and points in 3D simultaneously,我能够实现这一目标:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import numpy as np

fig = plt.figure()
ax = fig.gca(projection='3d')
ax.set_xlim(0, 1)
ax.set_ylim(0, 1)
ax.set_zlim(0, 1)

ax.set_xticks([0, 0.2, 0.4, 0.6, 0.8, 1])
ax.set_yticks([0, 0.5, 1])
ax.set_zticks([0, 0.2, 0.4, 0.6, 0.8, 1])
cmap = plt.cm.gray

#plot vertical surface
y = 0.5
xx, zz = np.meshgrid(np.linspace(0,1,10), np.linspace(0,1,10))
p = ax.plot_surface(xx, y, zz, cmap=cmap, alpha=0.5)

x = 0.2
yy, zz = np.meshgrid(np.linspace(0,1,10), np.linspace(0,1,10))
p = ax.plot_surface(x, yy, zz, cmap=cmap, alpha=0.5)

fig.colorbar(p)
plt.show()

请注意,我没有像其他问题一样使用normaldot,因为在这里您要绘制垂直平面。

这就是我得到的(我正在进行正确的咬合):

enter image description here