栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

将4D数据绘制为Python中的分层热图

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将4D数据绘制为Python中的分层热图

假设您有两个txt文件,即 data-z600.txtdata-z1200.txt ,与python脚本位于同一文件夹中,其内容完全相同

data-z600.txt (您的)

XA YA ZA GA200 0 600 1.27600 0 600 1.541200 0 600 1.491800 0 600 1.342400 0 600 1.273000 0 600 1.25200 600 600 1.28600 600 600 1.961200 600 600 1.121800 600 600 1.062400 600 600 1.063000 600 600 1.06

data-z1200.txt故意 发明)

XA YA ZA GA200 0 1200 1.31600 0 1200 21200 0 1200 1.631800 0 1200 1.362400 0 1200 1.313000 0 1200 1.35200 600 1200 1.38600 600 1200 1.361200 600 1200 1.21800 600 1200 1.12400 600 1200 1.13000 600 1200 1.11

让我们导入所有必需的库

# librariesfrom mpl_toolkits.mplot3d import Axes3Dimport matplotlib.pyplot as pltimport scipy.interpolate as sifrom matplotlib import cmimport pandas as pdimport numpy as np

和定义

grids_maker
,这并不准备包含在一个给定的文件数据的作业的功能,这里有针对性的 通过
filepath
论证。

def grids_maker(filepath):    # Get the data    df = pd.read_csv(filepath, sep=' ')    # Make things more legible    xy = df[['XA', 'YA']]    x  = xy.XA    y  = xy.YA    z  = df.ZA    g  = df.GA    reso_x = reso_y = 50    interp = 'cubic' # or 'nearest' or 'linear'    # Convert the 4d-space's dimensions into grids    grid_x, grid_y = np.mgrid[        x.min():x.max():1j*reso_x,        y.min():y.max():1j*reso_y    ]    grid_z = si.griddata(        xy, z.values,        (grid_x, grid_y),        method=interp    )    grid_g = si.griddata(        xy, g.values,        (grid_x, grid_y),        method=interp    )    return {        'x' : grid_x,        'y' : grid_y,        'z' : grid_z,        'g' : grid_g,    }

让我们使用

grids_maker
文件列表,获取每个文件第4维的极值。

# Let's retrieve all files' contentsfgrids = dict.fromkeys([    'data-z600.txt',    'data-z1200.txt'])g_mins = []g_maxs = []for fpath in fgrids.keys():    fgrids[fpath] = grids = grids_maker(fpath)    g_mins.append(grids['g'].min())    g_maxs.append(grids['g'].max())

让我们创建(所有文件统一)色标

# Create the 4th color-rendered dimensionscam = plt.cm.ScalarMappable(    norm=cm.colors.Normalize(min(g_mins), max(g_maxs)),    cmap='jet' # see https://matplotlib.org/examples/color/colormaps_reference.html)

…最后制作/显示情节

# Make the plotfig = plt.figure()ax  = fig.gca(projection='3d')for grids in fgrids.values():     scam.set_array([])       ax.plot_surface(        grids['x'], grids['y'], grids['z'],        facecolors  = scam.to_rgba(grids['g']),        antialiased = True,        rstride=1, cstride=1, alpha=None    )plt.show()



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/662206.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号