這段代碼:
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)
顯示以下圖:

我想擦除情節的地板。另外,我不知道為什么有些方塊比其他方塊更暗,即使它們的高度都相同。
uj5u.com熱心網友回復:
我認為最好的辦法是在圖表中繪制您實際想要的資料。這需要手動定義軸的限制。某些條形的較深顏色不取決于高度,但可能是人工制品,例如在某些情況下底面呈現在頂部。
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)

轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/353570.html
標籤:Python matplotlib 阴谋 条形图
上一篇:如何使用字典中的值注釋網格圖
下一篇:圖例未出現在3D圖中
