微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

matplotlib bar3d 中的可视化错误

如何解决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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?