如何解决matplotlib bar3d 中的可视化错误
我正在 matplotlib 中绘制 3D 条形图。
我发现了几个怪癖,当相邻条的条高度很大时,可视化是错误的。有没有人知道有什么解决办法?
隐形栏
使用该实施例中的代码:
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import matplotlib.cm as cm
power = 5
n = 5
x = [1,2,3,1,3] # x coordinates of each bar
x = []
x = [x+1 for x in range(n)]
x = x * n
y = []
for item in range(n):
y = y + [item]*n
#y = f # y coordinates of each bar
z = [0] * (n**2) # z coordinates of each bar
dx = [1] * (n**2) # Width of each bar
dy = [1] * (n**2) # Depth of each bar
dz = list(range(n**2))
dz = [x**power for x in dz]
fig = plt.figure(dpi=400) #create a canvas,tell matplotlib it's 3d
ax = fig.add_subplot(111,projection='3d')
max_height = np.max(dz) # get range of colorbars so we can normalize
min_height = np.min(dz)
# scale each z to [0,1],and get their rgb values
rgba = [cmap((k-min_height)/max_height) for k in dz]
ax.bar3d(x,y,z,dx,dy,dz,color=rgba,zsort='average')
plt.title(r"plot title")
plt.xlabel("x axis")
plt.ylabel("y axis")
plt.show()
将 power
变量设置为 3
,绘图很好。在 power=5
处,您可以看到数据点 (5,4) 不可见,显示后面的条。我相信这是由于条形高度之间的巨大差异。当我用高但相似的高度进行测试并且没有出现问题时。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。