如何修改以下情节?
How to modify the following plot?
下图还有一些未完成的修改。
我想将第一行设为红色。第二行蓝色第三行绿色
还有一点,['Bézier1'、'Bézier2'、'Bézier3']不在中间,怎么把它们往右移一点?
最后一件事,我想把 'Grid size' 放在中间。
我可以得到帮助吗?
这是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))
你可以替换这一行:
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])
下图还有一些未完成的修改。
我想将第一行设为红色。第二行蓝色第三行绿色
还有一点,['Bézier1'、'Bézier2'、'Bézier3']不在中间,怎么把它们往右移一点?
最后一件事,我想把 'Grid size' 放在中间。
我可以得到帮助吗?
这是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))
你可以替换这一行:
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])