I often use diverging colormaps (like the Paraview default "cool-to-warm") with a color range that is symmetric around zero, e.g. to visualize areas of tensile (red) and compressive (blue) stress with stress-free areas in a neutral color.

For this, I have to adjust the "Custom Data Range" by hand every time I load a new data set.

Can I automate this process? Maybe with a macro?

Unsymmetric color range:

Unsymmetric color range

Symmetric color range (what I want):

Symmetric color Range


1 Answer 1


I came up with a Paraview macro that sets a symmetric color range based on the color range that is currently set (maximum absolute value).

Note that the macro does not rescale the range based on the data. So if you load new data and want to adjust, you have to "Rescale to Range" first. The macro has no effect if the range is already symmetric.

Save the following code in a Python script, e.g. "SymmetrizeColorRangeMax.py" and then in Paraview: "Macros" → "Import new macro...".

from paraview.simple import *

source = GetActiveSource()
view = GetActiveView()
display = GetDisplayProperties(source, view=view)
cname = display.ColorArrayName[1]
ctf = GetColorTransferFunction(cname)

cmin = ctf.RGBPoints[0]
cmax = ctf.RGBPoints[-4]
cmaxabs = max(abs(cmin), abs(cmax))

ctf.RescaleTransferFunction(-cmaxabs, cmaxabs)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.