如何用Python中的离散数据集创建3d热图? [英] How to create a 3d Heatmap from a discrete data set in Python?

查看:117
本文介绍了如何用Python中的离散数据集创建3d热图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大型数据集,格式为[(X1,Y1,Z1,VALUE1),(X2,Y2,Z2,VALUE2)...]。这些点的几何形状是圆柱体的表面,虽然有许多离散点,它们远不及完整网格。



我想创建一个基本图,其中每个点都基于其值的高低来指定颜色的强度(如热图),然后将颜色平滑到一定程度以创建具有粘性的表面,而不是离散的点



我当前正在使用matplotlib,但是,如有必要,我还将使用其他库。



我已经研究了平面图和Tri-Surface图,但似乎都没有达到我想要的效果(尽管plot_trisurf()的文档有些混乱,所以也许仍然有可能)。
我也看了这篇文章:


I have a large dataset of the form [(X1, Y1, Z1, VALUE1), (X2, Y2, Z2, VALUE2)...]. The geometry of the points is the surface of a cylinder, while there are many discrete points they come nowhere near being a full mesh.

I would like to create a basic plot, where each of the points is given an intensity of a color (like a heatmap) based on how high its value is, and then the colors are smoothed to some degree to create a cohesive surface rather than discrete points

I am currently using matplotlib, however, I would also use other libraries if necessary.

I have looked into both surface plots and Tri-Surface plots but neither seem to do what I want (although the documentation for plot_trisurf() is a little confusing so maybe it is still a possibility). I have also looked at this post: 3D discrete heatmap in matplotlib.

And while the set up is mostly the same, I would like to have a more cohesive surface plot rather than a 3d Tetris set up. The original answer seems pretty close to my desired solution, however, I would like the colors to be based on VALUE rather than Z and if possible for there to be color smoothing between the sections.

解决方案

Depending on how dense your point cloud is you may be able to get what you want with this (adjust the size parameter, s, to fill out the plot best for your data):

from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.gca(projection='3d')
ax.scatter(X, Y, Z, c=Value, lw=0, s=20)
plt.show()

这篇关于如何用Python中的离散数据集创建3d热图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆