如何绘制下图?

How to plot the following figure?

亲爱的。我完全是 python 社区的初学者,我想在 python 中将下面的图片绘制为 3D。

我已经尝试过了,但是我没有取得任何成功的结果。 这是我的数据

下面是我的尝试:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
fig = plt.figure()
ax1 = fig.add_subplot(111, projection='3d')
# data
x = [86, 91, 97]
y = [82, 88, 94]
z = [80, 85, 89]
ax1.plot(x,y,z)
plt.show()

您的数据形状不正确。您提供了 3 个平面列表,您应该提供的是每个条形图的 x、y、z 坐标。

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

# create data
data_2d = [[729, 575, 528],
        [805, 768, 667],
        [841, 773, 724],
        [899, 857, 787]]

# Convert it into an numpy array.
data_array = np.array(data_2d)

# Create a figure for plotting the data as a 3D histogram.
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

# Create an X-Y mesh of the same dimension as the 2D data. The floor of the plot.
x_data, y_data = np.meshgrid( np.arange(data_array.shape[1]),
                              np.arange(data_array.shape[0]) )

# Flatten out the arrays so that they may be passed to "ax.bar3d".
# ax.bar3d expects three one-dimensional arrays:
# x_data, y_data, z_data. The following call boils down to picking
# one entry from each array and plotting a bar to from
# (x_data[i], y_data[i], 0) to (x_data[i], y_data[i], z_data[i]).

x_data = x_data.flatten()
y_data = y_data.flatten()
z_data = data_array.flatten()

dz = z_data
offset = dz + np.abs(dz.min())
fracs = offset.astype(float)/offset.max()
norm = colors.Normalize(fracs.min(), fracs.max())
color_values = cm.jet(norm(fracs.tolist()))

ax.bar3d( x_data, y_data, np.zeros(len(z_data)), 0.6, 0.6, z_data, color=color_values)

# Labels
ax.set_xlabel("Grid Size")
ax.set_ylabel("Bézier") 
ax.set_zlabel("Success Rate")
# Ticks
ax.set_zticks(range(0,1200,200))

# Shape of the 3D cube 
ax.set_box_aspect(aspect=(8,8,10))

输出: