This code:
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)
displays the following plot:
I would like to erase the floor of the plot. Additionally, I dont know why there are some squares that are darker than others even when the heigh are the same in all of them.
CodePudding user response:
I think your best bet is to just plot the data you actually want to have in the graph. This requires defining the limits of the axes manually. The darker colors of some of the bars don't depend on the height, but are presumably artifacts, e.g. the bottom face being rendered on top, on some occasions.
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)