python - 如何绘制布洛赫球中概率密度函数的 3_d 表示?
问题描述
我有一个模型,它为我提供特定形式的数据集。可以说它的半径+ 2个角度(r,phi,theta)。我想在 bloch 球体中绘制这些数据,其中两个体积表示 25% 或 75% 的数据点所在的区域。
这是我想在 2D 中可视化的示例。
我的想法是:
使用 np.histogramdd 对 3D 数据进行分箱
# transform my data onto a cartesian coordinate system X = amp * np.sin(2*chi) * np.cos(theta) Y = amp * np.sin(2*chi) * np.sin(theta) Z = amp * np.cos(2*chi) data_xyz=np.array([X,Y,Z]).T hist, binedges = np.histogramdd(data_xyz,bins=60, normed=False) list_of_weighted_entries = np.sort(np.reshape(hist,np.power(60,3))) weight_sum = np.sum(hist)
重塑分箱数据,以便我得到一个加权索引降序排列的列表,并定义阈值(25 或 75%)以定义哪些索引位于特定的 pdf 卷内:
#For 25 % cumu_weight = 0 index = 1 while cumu_weight < weight_sum * 0.25: cumu_weight = cumu_weight + list_of_weighted_entries[-index] index = index + 1 treshhold_value = list_of_weighted_entries[-(index-1)]
使用行进立方体来绘制这些体积
#calculate the bin_size for each direction diff0 = binedges[0][1] - binedges[0][0] diff1 = binedges[1][1] - binedges[1][0] diff2 = binedges[2][1] - binedges[2][0] verts, faces, normals, values = measure.marching_cubes_lewiner(hist, treshhold_value,(diff0,diff1,diff2)) fig = plt.figure(figsize=(10, 10)) ax = fig.add_subplot(111, projection='3d') mesh = Poly3DCollection(verts[faces],linewidths=0,facecolor="rosybrown") mesh.set_edgecolor('k') ax.add_collection3d(mesh)
添加一些绘图样式等......
这给了我一个非常漂亮的图像,但是出了点问题,因为体积不应该在透明球体之外+它是旋转的。在从垃圾箱转换回坐标的某个地方,我似乎搞砸了。
有人知道在哪里吗?
编辑:我现在很确定问题在于Poly3DCollection
绘图。问题是这个图总是从 0:0:0 开始,但我给 histogramm 函数的坐标也有负体积->我必须在计算“PDF 体积”后为我得到的数据添加翻译
这给了我一个非常漂亮的图像,但是出现了问题,因为体积不应该在透明球体之外(因为球体的半径是最大半径的 1.1 倍)。
解决方案
推荐阅读
- php - 如何在视图功能中使用成功消息以及 withDetails?
- node.js - 当用户从托管在 Digital Ocean 上的 Web 应用程序将图像上传到 AWS S3 时,是出站还是入站带宽传输?
- javascript - 从 API 获取所有数据
- swiftui - 如何在 SwiftUI 中设置图像色调?
- c - 这个 MIPS 程序应该花这么长时间吗?(近似于 pi 的程序)
- ios - 使用 NSBatchInsertRequest 将自定义数组插入 CoreData
- javascript - 如何从 microsoft graph 获取刷新令牌
- html - 媒体查询没有响应
- axapta - “控件修改的名称必须是基本形式的控件。”
- sql - 加入 2 个多对多表并获得 3 个相邻的布尔列