擦除 matplotlib 3D 条形图的底部
Erasing the floor of a matplotlib 3D barplot
此代码:
import numpy as np
import matplotlib.pyplot as plt
# setup the figure and axes
fig = plt.figure(figsize=(8, 8))
ax = plt.axes(projection='3d')
# fake data
_x = np.arange(10)
_y = np.arange(10)
_xx, _yy = np.meshgrid(_x, _y)
x, y = _xx.ravel(), _yy.ravel()
top = np.zeros(shape=100)
top[0] = 10
bottom = np.zeros(shape=100)
width = depth = 1
ax.bar3d(x, y, bottom, width, depth, top, shade=True)
显示以下图:
我想把地块擦掉。另外,我不知道为什么有些方块比其他方块更暗,即使所有方块的高度都相同。
我认为你最好的选择是只在图表中绘制你真正想要的数据。这需要手动定义轴的界限。一些条形的较深颜色不取决于高度,但可能是人工制品,例如在某些情况下,底面被渲染在上面。
import numpy as np
import matplotlib.pyplot as plt
# setup the figure and axes
fig = plt.figure(figsize=(8, 8))
ax = plt.axes(projection='3d')
#=========================
ax.set_xlim([-0.5, 10.5])
ax.set_ylim([-0.5, 10.5])
#=========================
# fake data
_x = np.arange(10)
_y = np.arange(10)
_xx, _yy = np.meshgrid(_x, _y)
x, y = _xx.ravel(), _yy.ravel()
top = np.zeros(shape=100)
top[0] = 10
bottom = np.zeros(shape=100)
width = depth = 1
#=========================
x, y, top, bottom = np.stack([x, y, top, bottom])[:, top > 0]
#=========================
ax.bar3d(x, y, z=bottom, dx=width, dy=depth, dz=top, shade=True)
此代码:
import numpy as np
import matplotlib.pyplot as plt
# setup the figure and axes
fig = plt.figure(figsize=(8, 8))
ax = plt.axes(projection='3d')
# fake data
_x = np.arange(10)
_y = np.arange(10)
_xx, _yy = np.meshgrid(_x, _y)
x, y = _xx.ravel(), _yy.ravel()
top = np.zeros(shape=100)
top[0] = 10
bottom = np.zeros(shape=100)
width = depth = 1
ax.bar3d(x, y, bottom, width, depth, top, shade=True)
显示以下图:
我想把地块擦掉。另外,我不知道为什么有些方块比其他方块更暗,即使所有方块的高度都相同。
我认为你最好的选择是只在图表中绘制你真正想要的数据。这需要手动定义轴的界限。一些条形的较深颜色不取决于高度,但可能是人工制品,例如在某些情况下,底面被渲染在上面。
import numpy as np
import matplotlib.pyplot as plt
# setup the figure and axes
fig = plt.figure(figsize=(8, 8))
ax = plt.axes(projection='3d')
#=========================
ax.set_xlim([-0.5, 10.5])
ax.set_ylim([-0.5, 10.5])
#=========================
# fake data
_x = np.arange(10)
_y = np.arange(10)
_xx, _yy = np.meshgrid(_x, _y)
x, y = _xx.ravel(), _yy.ravel()
top = np.zeros(shape=100)
top[0] = 10
bottom = np.zeros(shape=100)
width = depth = 1
#=========================
x, y, top, bottom = np.stack([x, y, top, bottom])[:, top > 0]
#=========================
ax.bar3d(x, y, z=bottom, dx=width, dy=depth, dz=top, shade=True)