【问题标题】:How to modify the following plot?如何修改以下情节?
【发布时间】:2021-10-10 11:24:02
【问题描述】:

下图有一些未完成的修改。

我想将第一行设为红色。第二行蓝色,第三行绿色。

还有一点,['Bézier1', 'Bézier2', 'Bézier3'] 不在中心,我怎样才能将它们向右移动一点?

最后一件事,我想把“网格大小”放在中间。

我可以得到帮助吗?

这是 Python 的代码

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

# create data
data_2d = [[86, 82, 80],
          [91, 88, 85],
          [97, 94, 89]]

# 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(figsize=(10,8), dpi=100)
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()

ax.bar3d( x_data, y_data, np.zeros(len(z_data)), 0.7, 0.7, z_data, color='r')


# Labels
ax.set_xlabel("Grid Size", labelpad=18)
ax.set_ylabel("Bézier curve-based approaches", labelpad=15, loc='center') 
ax.set_zlabel("Success Rate")

ys=['Bézier1', 'Bézier2', 'Bézier3']
xs=['30x30', '50x50', '100x100']

# Ticks
ax.set_zticks(range(0,120,20))
ax.set(xticks=range(len(xs)), xticklabels=xs,
       yticks=range(len(ys)), yticklabels=ys) 
plt.xticks(rotation = 50)


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

【问题讨论】:

    标签: python matplotlib 3d


    【解决方案1】:

    你可以替换这一行:

    ax.bar3d( x_data, y_data, np.zeros(len(z_data)), 0.7, 0.7, z_data, color='r')
    

    用这个块:

    colors = ['r','b','g']
    for i in [0,3,6]:
        ax.bar3d( x_data[i:i+3], y_data[i:i+3], np.zeros(len(z_data[i:i+3])), 0.7, 0.7, z_data[i:i+3], color=colors[i//3])
    

    【讨论】:

    • 非常感谢亲爱的先生。颜色问题已经解决了。
    猜你喜欢
    • 1970-01-01
    • 2020-07-17
    • 1970-01-01
    • 2016-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多