怎样在Paraview的python脚本中设置颜色表范围?

2024-05-16 20:00:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在Paraview中可视化一个空间数据的时间序列,我希望我的设置脚本能够根据字段在整个时间序列中的范围来设置给定字段的颜色表,而不是单个快照。我尝试初始化查找表,但没有用脚本计算出值。在

下图显示了运行安装脚本的结果。pythonshell窗口中的值是比例应该设置的值,但是颜色栏显示另一个值。在

results of running the setup script. The values in the Python Shell window are what the scales should be set to, but the color bar shows another value

这里是我的设置脚本的相关部分。在

# get the scales for the surface fields
mag_os_xdmf = FindSource('mag_os.xdmf')
with h5py.File(mag_os_xdmf.FileName.replace('xdmf', 'h5'), 'r') as h5:
    for comp in ('br', 'bt', 'bp'):
        scale = np.abs(h5[comp].value).max()
        print(comp, scale)
        ctab = [-scale, 0.23137254901960785, 0.2980392156862745, 0.7529411764705882,
                scale, 0.7058823529411765, 0.01568627450980392, 0.14901960784313725]
        DataRep = GetDisplayProperties(mag_os_xdmf)
        lut = GetLookupTableForArray(comp, 1, NanColor=[0.24705882352941178, 0.0, 0.0],
                                     RGBPoints = ctab, ColorSpace='Diverging' )
        DataRep.ColorArrayName = ('POINT_DATA', comp)
        DataRep.LookupTable = lut
Render()

作为比较,下面是我手动更改colorbar时python跟踪的输出

^{pr2}$

Tags: the脚本foros颜色时间序列h5
1条回答
网友
1楼 · 发布于 2024-05-16 20:00:33

您应该能够执行以下操作:

# get color transfer function/color map for 'br'
lut = GetColorTransferFunction('br')

# get opacity transfer function/opacity map for 'br'
opacityLut = GetOpacityTransferFunction('br')

# Rescale transfer function
lut.RescaleTransferFunction(-scale, scale)

# Rescale transfer function
opacityLut.RescaleTransferFunction(-scale, scale)

相关问题 更多 >