Render 3 dimensional scalar field I have a function which assigns to "every" point in space (x,y,z) a scalar value d. I want to, somehow, visualize this function using Blender. This could be done with interpreting the value d as some kind of density and rendering coloured glass which absorbs more light at higher density values and seems transparent at lower density values.

I found the material type Volume to be in the proximity of what I am looking for but I do not know how to control the density at the points in space.

Has anyone an idea how to do this? Some solution with python is desirable.
Bender uses python for the user interface and it can also automate many tasks that manipulate blenders data. However when you want to customise a material python isn't much help.

If you want to use blender internal render engine you will find that there is some support for external voxel data.

For cycles, I think your best option would be an OSL shader.

I made a quick sample script as a starting point for you -

float myFunc(float x, float y, float z)
{
    return 1.5;
}

shader MyVolShader(
    color   BaseColour = color(1.0,0.0,0.0),
    output closure color Volume = 0)
{
    // P is the current point
    // P[0] == x
    // P[1] == y
    // P[2] == z
    Volume = (BaseColour * myFunc(P[0], P[1], P[2])) * absorption();
}


You then fillin myFunc using your algorithm, and the final colour as desired.

If you want volume scattering, swap absorption() with henyey_greenstein(0.0) in the final calculation (or add them together).

The OSL Language reference should be helpful.

I have a collection of OSL scripts here but none that use volume yet.