matplotlib - 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, 2, 3, 1, 2, 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) 不可见,显示后面的条形。我相信这是由于酒吧高度之间的巨大差异。当我用高但相似的高度进行测试并且问题不会发生时。
解决方案
推荐阅读
- unity3d - 如何旋转对象以沿矢量 Unity3D 指向
- python - 将数据添加到 CSV 文件的新列和第一行
- angular - 错误 TS2304:部署云功能 firebase 时找不到名称“元素”
- selenium - NightwatchJS - 手动运行 Selenium 服务器时无法创建会话
- vba - VBA,带工作表,清除表格内容
- spring-boot - Spring Boot @Pattern 自定义消息不起作用
- javascript - Chartist 关于没有 jQuery 的点击功能
- ios - 重用“昂贵”的 UIViewController
- angular - Angular - 由 *ngFor 创建的输入会导致在触发模糊事件时显示重复值
- python - 在python中的列表列表上使用定义的函数